gpt4 book ai didi

mysql - 需要对 MySQL 连接查询进行计数

转载 作者:行者123 更新时间:2023-11-29 00:53:35 26 4
gpt4 key购买 nike

查看了具有相似标题的问题,没有任何问题足以让这个查询正常工作。我知道这可能相当简单。

实际查询是这样的:

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')

但这会抛出一个非描述性错误并且不会运行。

最佳答案

你到底想数什么?只是行数?使用 COUNT(*)。使用 COUNT(column) 计算该列中的所有非 NULL 值。

查询将只返回一行,即计数。

select count(*) as count
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')

关于mysql - 需要对 MySQL 连接查询进行计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7206310/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com