gpt4 book ai didi

mysql - 获取具有唯一或不同值的表?

转载 作者:太空宇宙 更新时间:2023-11-03 11:16:14 25 4
gpt4 key购买 nike

我有这张表:

post{id, user_id, event_id}

我想为特定用户获取所有具有 event_id(非 NULL)的帖子,并且我不希望 event_id 再次出现,我希望它是不同的,即如果 2 个帖子的 event_id 为 2,则我只需要取回其中一个,谢谢!!!

select count(*)
from posts
where user_id = '43'
and
//not null event id
//distinct event id's

最佳答案

试试这个来获取事件 ID 的计数:

SELECT COUNT(DISTINCT event_id)
FROM posts
WHERE user_id = '43'
AND event_id IS NOT NULL

关于mysql - 获取具有唯一或不同值的表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4834600/

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