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

查看:120
本文介绍了LIMIT中的MySQL Math和COUNT(*)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以让MySQL LIMIT的行总数除以2,所以查询看起来像这样:

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:

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

5只是数字.

推荐答案

不可能.

文档:

表达式可以在SQL语句中的多个点使用,例如在SELECT语句的ORDER BY或HAVING子句,SELECT,DELETE或UPDATE语句的WHERE子句中或在SET语句中.

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.

也来自 SELECT文档:

LIMIT子句可用于约束SELECT语句返回的行数. LIMIT接受一个或两个数字参数,这两个参数都必须是非负整数常量(使用预处理语句时除外).

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 (except when using prepared statements).

您将必须执行两个查询-一个进行计数,另一个进行限制.

You will have to do two queries--one to count, the other to limit.

这篇关于LIMIT中的MySQL Math和COUNT(*)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆