我正在尝试返回2列:星期几和当天发生的次数。我如何返回每天的出现次数?
SELECT case CAST(strftime('%w', HireDate) AS INTEGER)
WHEN 0 then 'Sunday'
WHEN 1 then 'Monday'
WHEN 2 then 'Tuesday'
WHEN 3 then 'Wednesday'
WHEN 4 then 'Thursday'
WHEN 5 then 'Friday'
ELSE 'Saturday' END AS 'Day of week', AS 'Hired'
FROM Employee;
答案 0 :(得分:0)
只需在group by子句中重写案例:
SELECT
( case CAST(strftime('%w', HireDate) AS INTEGER)
WHEN 0 then 'Sunday'
WHEN 1 then 'Monday'
WHEN 2 then 'Tuesday'
WHEN 3 then 'Wednesday'
WHEN 4 then 'Thursday'
WHEN 5 then 'Friday'
ELSE 'Saturday' END ) AS 'Day of week',
count(*) AS 'Hired' --<--here
FROM
Employee
GROUP BY --<--here
( case CAST(strftime('%w', HireDate) AS INTEGER)
WHEN 0 then 'Sunday'
WHEN 1 then 'Monday'
WHEN 2 then 'Tuesday'
WHEN 3 then 'Wednesday'
WHEN 4 then 'Thursday'
WHEN 5 then 'Friday'
ELSE 'Saturday' END );