0

我有一个表,其中我接受了图像,拒绝的图像,并在单列中更改了图像,动作列具有动作 2 接受的图像,动作 3 - 拒绝的图像,动作 4 - 更改图像。我可以在“接受的图像”上运行,但我也希望为被拒绝的图像设置一个不同的列。但无法做到这一点。我是mysql新手,请帮助我。如何为被拒绝的图像获取不同的列

select  message,  date(datetime) as dateonly ,count(message)
from customer_1.audit_trail where message in ('Accepted Images') 
group by dateonly  order by dateonly asc limit 100;


 message,      dateonly, count(message)
"Accepted Images",2007-08-07,  79
"Accepted Images",2007-08-08,52
4

5 回答 5

0

为接受和拒绝创建不同的查询。然后联合两者。

于 2013-07-29T13:10:18.483 回答
0

如果它不需要在单独的列中(从您的描述中并不清楚),那么您可以这样做:

select  message,  date(datetime) as dateonly, count(message)
from customer_1.audit_trail 
group by message, dateonly  
order by dateonly asc limit 100;

否则你将不得不旋转消息列

于 2013-07-29T12:04:35.267 回答
0

你上面的查询是错误的。您可能永远不会得到消息列输出,因为在您的分组列中,您只有 dateonly。

select  date(`datetime`) as dateonly ,
count(case when message= 'Accepted Images' then 1 else 0 end ) as accepted_image_count,
count(case when message= 'Rejected Images' then 1 else 0 end ) as  rejected_image_count
from customer_1.audit_trail where message in ('Accepted Images','Rejected Images') 
group by dateonly  order by dateonly asc limit 100;
于 2013-07-29T12:05:27.317 回答
0
SELECT  message,  date(datetime) as dateonly ,
sum(CASE message when 'Accepted Images' then 1 else 0 end) as CNT_Accepted,
sum(CASE message when 'Rejected Images' then 1 else 0 end) as CNT_Rejected
FROM customer_1.audit_trail 
WHERE message in ('Accepted Images') 
GROUP BY dateonly, message
ORDER BY dateonly asc limit 100;

这是一种方式。

于 2013-07-29T12:06:16.440 回答
0

试试这样的。
将你的 sql 表分成 3 列(image_id、action、date)

然后根据图像 id 更新 action 和 date 列或插入到表中;
ex sql
update yourTable set action='Accepted Images',date='2013-01-01' where image_id='1';
插入你的表值('1','Accepted Images',2013-01-01);

然后您可以根据操作状态检索数据,
例如 sql
select image_id,date, from yourTable where action='Accepted Images' group by date order by date asc limit 100;

如果需要任何其他列,您可以根据需要对其进行管理。下次尝试清楚地了解您的问题。

于 2013-07-29T12:07:06.333 回答