0

我有一个查询,我必须从一个表中查看 3 列,其中我在 message 列上搜索了 2 列,最后一列应该在 like 上。我怎样才能同时使用这两个语句。

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 ;
4

1 回答 1

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 ;
于 2013-07-30T09:24:31.740 回答