Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rownum怎么用 #1503

Open
overlbjn opened this issue Aug 6, 2020 · 1 comment
Open

rownum怎么用 #1503

overlbjn opened this issue Aug 6, 2020 · 1 comment

Comments

@overlbjn
Copy link

overlbjn commented Aug 6, 2020

SELECT t.*,@rownum := @rownum + 1 AS rank_num FROM (SELECT @rownum := 0) r,(SELECT user_id,SUM(coin) AS total FROM test GROUP BY user_id ORDER BY total DESC) AS t

怎么用think.model()完成同样的效果?不用think.model.query(sql)

@lizheming
Copy link
Contributor

复杂语句使用 where(), field(), select() 去写的话最后可能和直接写 SQL 的效果差不多(SELECT 列那块肯定是只能写字符串了)。所以如果真的需要使用复杂语句的话建议是直接用 query() 去写 SQL 语句比较好。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants