查找包含2个不同日期的一个值的列

时间:2014-03-18 22:02:10

标签: mysql sql

我有下表:

表1

列如下:

date , time , user_id , channel

我希望找到一个在2个不同日期,频道(比如CNN,NBC ......)观看所有相关条目的用户列表。

表示日期1和日期2中的频道相同,也就是user_id。

我尝试了以下内容:

select distinct  monthname(date),max(date), min(date) count(distinct user_id)   
from iptv_clean 
group by  monthname(date) 
having min(date)!= max(date)

但似乎效果不好。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

以下列出了用户在多个日期观看的用户和频道列表:

select user_id, channel, count(distinct date)   
from iptv_clean 
group by user_id, channel
having count(distinct date) > 1;

这是你想要的吗?