Dear 版友:
我想统计数据库的月或周的资料
网络上我有看到
http://ben.goodacre.name/tech/Group_by_day,_week_or_month_%28PostgreSQL%29
我测试了一下
SELECT date_trunc('week',date(build_date)) AS "Week" , count(*) AS "Total"
FROM data_input
WHERE date(build_date) > now() - interval '5 year'
GROUP BY 1
ORDER BY 1;
A build_date 格式为 20131101(YYYYMMDD)这样子的格式,SQL执行正确
B build_date 格式为 20131101133311(年月日时分秒),这样子就会出现错误
看来是格式转换问题,不知道 B有没有办法转成时间格式?