需要获取 MySQL 连接查询的计数

发布于 2024-12-01 11:42:30 字数 808 浏览 1 评论 0原文

浏览了具有相似标题的问题,没有任何内容足够接近以使该查询正常工作。我知道这可能是相当简单的事情。

实际的查询是这样的:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浅唱ヾ落雨殇 2024-12-08 11:42:30

你到底想算什么?只是行数?使用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')

What exactly do you want to count? just the number of rows? use COUNT(*). use COUNT(column) to count all non-NULL values in this column.

The query will then only return a single row, the count.

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')
心在旅行 2024-12-08 11:42:30

你应该使用简单的

Select count(entries.id)  ....

You should use simple

Select count(entries.id)  ....
弄潮 2024-12-08 11:42:30
select count(1) 

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(1) 

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')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文