在 mysql 的 limit 子句中可以有一个子查询吗?我试图在一个查询中只从同一个表中选择总行数的 10%。
SELECT * FROM table LIMIT (SELECT (10 * COUNT(*)/100) FROM table);
关于如何实现这一点有什么建议吗?
最佳答案
你问:
Is it possible to have a subquery inside a limit clause in mysql?
答案基本是否定的。
读这个:
http://dev.mysql.com/doc/refman/5.6/en/select.html
The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be nonnegative integer constants, with these exceptions:
Within prepared statements, LIMIT parameters can be specified using ? placeholder markers.
Within stored programs, LIMIT parameters can be specified using integer-valued routine parameters or local variables.
关于限制子句内的Mysql子查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21541772/