将MySQL DATE_FORMAT转换为PostgreSQL

时间:2017-05-19 02:11:17

标签: sql postgresql

如何将MySQL DATE_FORMAT转换为POstgreSQL?

我有MySQL SQL查询:

SELECT DATE_FORMAT(FROM_UNIXTIME(time_created), '%Y') AS year, 
DATE_FORMAT(FROM_UNIXTIME(time_created) , '%m') AS month , 
COUNT(guid) AS total 
FROM ossn_users  
WHERE(time_created > 0) 
GROUP by DATE_FORMAT(FROM_UNIXTIME(time_created) ,  '%Y%m');

我将其转换为:

SELECT to_char(to_timestamp(time_created), 'YYYY') AS year,
to_char(to_timestamp(time_created) , 'MM') AS month,
COUNT(guid) AS total 
FROM ossn_users  
WHERE(time_created > 0) 
GROUP by to_char(to_timestamp(time_created),'YYYY'), to_char(to_timestamp(time_created),'MM')  ;

但它似乎不起作用。

请问,什么是正确的转换?

这次转换是对的吗?

谢谢。

0 个答案:

没有答案