我需要一些 MySQL 痛苦的帮助 ****... 无论如何,我得到了以下 sql:
SELECT id,count(*),
CASE
WHEN count(*) > 1 THEN
// I need the minimal `taskdate_time` column from the selected rows
// where a certain boolean is active
ELSE taskdate_time
END
FROM timehistory th
WHERE `send`=true
GROUP BY date_format(taskdate_time, "%Y-%m-%d"), user_id
如评论中所述,我需要为removed
没有调用列的两行获取最早的超时时间FALSE
我如何实现这一目标?
我的专栏是:
`id` - int
`taskdateuser_id` int
`user_id` int
`changed_by` int
`batch_id` int
`taskdate_time` timestamp
`send` tinyint
`isread` tinyint
`update` tinyint
`removed` tinyint
提前谢谢了!!!
编辑:
我可能会再解释一下。如果我得到下表行:
红色标记的行由 CASE count(*) > 1 捕获,因为 group by 返回了 2 行。然后我需要从 2 个捕获的行中选择一个 SELECTremoved=false
和min(taskdate_time)
. 因此,如果为该分组返回 4 行,并且其中 2 行是removed=false
,而另一行是,removed=true
那么我需要对taskdate_time
2 行 where的最小值进行子选择removed=false
。