我有三列StartDate,Department,Tripduration(StartDate Column在" MM / dd / yyyy"需要转换" yyyy-MM-dd")
要求是查询每个月的数据。按部门分组
任何帮助都会受到赞赏吗?
答案 0 :(得分:1)
你可以转换" MM / dd / yyyy"到" yyyy-MM-dd"这样。
select TO_DATE(FROM_UNIXTIME(UNIX_TIMESTAMP(StartDate, 'dd/MM/yyyy'))) as month
from your_table;
和分组(月和部门)
select
MONTH(TO_DATE(FROM_UNIXTIME(UNIX_TIMESTAMP(StartDate, 'dd/MM/yyyy')))) as month,
Department,
sum(Tripduration) --or avg or whatever you want
from your_table
group by MONTH(TO_DATE(FROM_UNIXTIME(UNIX_TIMESTAMP(StartDate, 'dd/MM/yyyy')))), Department;