如何在MySQL中使用正则表达式where where和in语句在where子句中

时间:2013-07-30 09:22:59

标签: mysql

我有一个查询,我必须从一个表中查看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 ;

1 个答案:

答案 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 ;