我的问题是,我有一个数据库,它以这种方式保存数据。例如,你已经发布了一些东西,但有到类型的帖子。另一个是周刊和每日邮报。在我的数据库中,我有一列告诉我它是每周还是每日帖子。
id | senderID | message | weekly | daily
1 5 "hello" 1 0
2 5 "Fun joke" 0 1
那么,我如何能够选择这两行到一行,如果他们做了每周和每天的消息,行应该看起来像这样
senderID | message | weekly | daily
5 "hello" 1 1
但是,如果发送者没有完成日常消息,它会显示
senderID | message | weekly | daily
5 "hello" 1 0
发布于 2016-07-25 05:24:11
试试这个:
select
senderid,
case when sum(weekly) > 0 then 1 else 0 end [weekly],
case when sum(daily) > 0 then 1 else 0 end [daily]
from TABLENAME
group by senderid
将TABLENAME
替换为实际的表名:)
https://stackoverflow.com/questions/38556875
复制相似问题