需要获取 MySQL 连接查询的计数
浏览了具有相似标题的问题,没有任何内容足够接近以使该查询正常工作。我知道这可能是相当简单的事情。
实际的查询是这样的:
select entries.id, entry_id, user_id, person_id, campaign_id, mood_id, entries.created, deleted_date, entries.modified, entry_type, walking_hash
from entries, users
where users.id = entries.user_id and users.is_deleted = 0 and entries.is_deleted = 0
and entries.entry_type in ('xyz', 'abc', 'def', 'lmno')
为了获取计数,我尝试了以下方法:
select count(entries.id, entry_id, user_id, person_id, campaign_id, mood_id, entries.created, deleted_date, entries.modified, entry_type, walking_hash)
from entries, users
where users.id = entries.user_id and users.is_deleted = 0 and entries.is_deleted = 0 and entries.entry_type in ('xyz', 'abc', 'def', 'lmno')
但这会引发非描述性错误并且不会运行。
Looked through the questions with similar titles and nothing was close enough to get this query working. I know this is probably something fairly simple though.
The actual query is this:
select entries.id, entry_id, user_id, person_id, campaign_id, mood_id, entries.created, deleted_date, entries.modified, entry_type, walking_hash
from entries, users
where users.id = entries.user_id and users.is_deleted = 0 and entries.is_deleted = 0
and entries.entry_type in ('xyz', 'abc', 'def', 'lmno')
To get the count I tried this:
select count(entries.id, entry_id, user_id, person_id, campaign_id, mood_id, entries.created, deleted_date, entries.modified, entry_type, walking_hash)
from entries, users
where users.id = entries.user_id and users.is_deleted = 0 and entries.is_deleted = 0 and entries.entry_type in ('xyz', 'abc', 'def', 'lmno')
but that throws a non-descript error and doesn't run.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你到底想算什么?只是行数?使用
COUNT(*)
。使用COUNT(column)
计算该列中所有非 NULL 值的数量。然后,查询将仅返回一行,即计数。
What exactly do you want to count? just the number of rows? use
COUNT(*)
. useCOUNT(column)
to count all non-NULL values in this column.The query will then only return a single row, the count.
你应该使用简单的
You should use simple