我有一个查询,我必须从一个表中查看3列,其中我在消息列上搜索了2列,最后一列应该在上面。我怎样才能一次使用两个语句。
SELECT date(datetime) as dateonly ,
sum(CASE message when 'Accepted Images' then 1 else 0 end) as AcceptedIMG,
sum(CASE message when 'Rejected Images' then 1 else 0 end) as RejectedIMG,
sum(CASE when message like '%Changed to %' then 1 else 0 end) as ChangeIMG
FROM customer_1.audit_trail
WHERE message like ('%Changed to %') and message in ('Accepted Images','Rejected Images')
GROUP BY (dateonly)
ORDER BY (dateonly) asc ;
答案 0 :(得分:0)
您可以使用OR(并将您的条件分组)
SELECT date(datetime) as dateonly ,
sum(CASE message when 'Accepted Images' then 1 else 0 end) as AcceptedIMG,
sum(CASE message when 'Rejected Images' then 1 else 0 end) as RejectedIMG,
sum(CASE when message like '%Changed to %' then 1 else 0 end) as ChangeIMG
FROM customer_1.audit_trail
WHERE (message like ('%Changed to %') OR message in ('Accepted Images','Rejected Images'))
GROUP BY (dateonly)
ORDER BY (dateonly) asc ;