如何将月份从unix时间戳从数字转换为月份名称?

时间:2017-09-26 06:24:00

标签: mysql sql select timestamp

我已经从谷歌图表中绘制图表了。这是图表

enter image description here

这是我的sql

$sql = 'SELECT ljj.job_id, SUM(CASE WHEN ljj.job_type = "0" THEN 1 ELSE 0 END) AS jobcount, SUM(CASE WHEN ljj.job_type = "1" THEN 1 ELSE 0 END) AS interncount, MONTH(FROM_UNIXTIME(ljj.job_timepublished)) AS month FROM {local_jobs_job} ljj INNER JOIN {local_jobs_location} ljl ON ljj.job_location = ljl.location_id INNER JOIN {local_companydetail} lc ON ljj.job_company_userid = lc.userid WHERE lc.link = "1" GROUP BY MONTH(FROM_UNIXTIME(ljj.job_timepublished))';

如何将数字中的月份转换为Jan,March,July等名称?

1 个答案:

答案 0 :(得分:1)

您可以使用monthname功能代替month

SELECT     ljj.job_id, 
           SUM(CASE WHEN ljj.job_type = "0" THEN 1 ELSE 0 END) AS jobcount, 
           SUM(CASE WHEN ljj.job_type = "1" THEN 1 ELSE 0 END) AS interncount, 
           MONTHNAME(FROM_UNIXTIME(ljj.job_timepublished)) AS "month" -- Here!
FROM       {local_jobs_job} ljj 
INNER JOIN {local_jobs_location} ljl ON ljj.job_location = ljl.location_id
INNER JOIN {local_companydetail} lc ON ljj.job_company_userid = lc.userid
WHERE      lc.link = "1"
GROUP BY   MONTHNAME(FROM_UNIXTIME(ljj.job_timepublished)) -- And here!