我有YYYYMMDD格式的日期int列,我想按一個月即yyyymm.I've嘗試以下集團從年月日INT列YYYYMM - PostgreSQL的
兩個版本select to_char(to_timestamp(create_dt),'YYYYMM'),count(*) from table_name
group by to_char(to_timestamp(create_dt),'YYYYMM')
order by to_char(to_timestamp(create_dt),'YYYYMM') desc
和
select to_char(create_dt,'YYYYMM'),count(*) from table_name
group by to_char(create_dt,'YYYYMM')
order by to_char(create_dt,'YYYYMM') desc
,當你想這些版本發生了什麼? – lurker
@lurker只有1行,您的查詢與我發佈的第二個查詢類似。 「YYYYMM」; 733103965。我將該列轉換爲一個字符串,並使用子字符串以第6個字符進行分組。 –