编写报告请求时出现问题,这反映了每天创建和更新事件的数量。
该表包括:
FieldTypeComment
id int (11) NOT NULL
name varchar (255) NULL
created_on datetime NOT NULL
updated_on datetime NOT NULL
创建和更新日期可能不一致。
请求:
SELECT
z.date_created,
SUM (IF (z.date_created = z.date_updated, 1, 0)) AS created,
SUM (IF (z.date_created! = Z.date_updated, 1, 0)) AS updated
FROM
(
SELECT
SUBSTRING (e.updated_on, 1, 10) AS date_updated,
SUBSTRING (e.created_on, 1, 10) AS date_created
FROM
event e
) z
GROUP BY
z.date_created
我需要以下结果:
未提供所需结果,因为未显示所有日期。
答案 0 :(得分:1)
假设你想要
create
; update
:http://www.sqlfiddle.com/#!2/56254/39
SELECT A.*
,(SELECT count(created_on)
FROM event WHERE date=created_on) created
,(SELECT sum(created_on<>updated_on)
FROM event WHERE date=updated_on) updated
FROM (
SELECT created_on date FROM event
UNION SELECT updated_on FROM event ) A
答案 1 :(得分:0)
要获取特定日期创建和更新的事件数量,请执行以下操作。
select count(*) events
from event
where
(created_on >= {d '2013-02-10'} and created_on < {d '2013-02-11'})
or
(updated_on >= {d '2013-02-10'} and updated_on < {d '2013-02-11'})
此方法会考虑这些字段的时间部分。