简体   繁体   English

LIM Math中的MySQL Math和COUNT(*)

[英]MySQL Math and COUNT(*) in LIMIT

Is it possible to let MySQL LIMIT have an offset of the total number of rows divided in 2, so that the query would look something like this: 是否可以让MySQL LIMIT的行总数偏移为2,这样查询看起来像这样:

SELECT * FROM test LIMIT COUNT(*) / 2, 5

Where 5 is just a number. 其中5只是一个数字。

It is not possible. 这不可能。

From the documentation : 文档

Expressions can be used at several points in SQL statements, such as in the ORDER BY or HAVING clauses of SELECT statements, in the WHERE clause of a SELECT, DELETE, or UPDATE statement, or in SET statements. 表达式可以在SQL语句中的多个点使用,例如SELECT语句的ORDER BY或HAVING子句,SELECT,DELETE或UPDATE语句的WHERE子句或SET语句中。

Also from the SELECT documentation : 另外还有SELECT文档

The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT子句可用于约束SELECT语句返回的行数。 LIMIT takes one or two numeric arguments, which must both be nonnegative integer constants (except when using prepared statements). LIMIT需要一个或两个数字参数,它们都必须是非负整数常量(使用预准备语句时除外)。

You will have to do two queries--one to count, the other to limit. 您将不得不做两个查询 - 一个要计数,另一个要限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM