我在下面查询:
SELECT year(time_of_creation), month(time_of_creation), group_concat(time_to_sec(last_updated) - time_to_sec(time_of_creation)) from my_table where status='s' group by year(time_of_creation), month(time_of_creation);
我期望这样做是否有一个包含以下列的表:
status
time_of_creation
last updated
我希望(year, month)
能够对每个条目进行分区,并且我希望以逗号分隔的两个字段(last_updated
,time_of_creation
之间的每一行的时间差(秒)列表。
但是,我上面的查询似乎返回的数字与我通过表格在视觉上检查的数字不匹配。
我的查询写得不正确吗?
答案 0 :(得分:0)
试试这个。
SELECT
CONCAT_WS(" , ", year(time_of_creation),month(time_of_creation))
,
group_concat(TIME(time_to_sec(last_updated) - time_to_sec(time_of_creation)))
FROM my_table
where status='s'
and IFNULL(last_updated,0) > 0
group by year(time_of_creation), month(time_of_creation);