如何根据月份对出勤日期进行排序?

时间:2018-05-09 07:26:06

标签: postgresql sorting

出勤是根据日期排序,这很好,但我想将日期与月份名称一起排序 1月应该在底部,12月在顶部。

Attendance Date
---------------
26 Feb 2018
19 Dec 2018
18 Dec 2018
14 Dec 2018
12 June 2018
7 Dec 2018
5 Feb 2018

查询

select distinct 
    (select ARRAY_TO_STRING(ARRAY_AGG(ARRAY[to_char(t1.l_time,'HH12:mi AM')]::text), ',')
     from
         (select (al1.create_time AT TIME ZONE 'UTC+5:30')::time as l_time
          from users.access_log as al1
          where al1.user_id = al.user_id
            and al1.login_status = 1
            and al1.create_time::date = al.create_time::date
          order by al1.create_time::time ASC
         ) as t1
    ) as login_time,
    (select ARRAY_TO_STRING(ARRAY_AGG(ARRAY[to_char(t2.o_time,'HH:mi AM')]::text), ',')
     from
         (select (al2.create_time AT TIME ZONE 'UTC+5:30')::time as o_time
          from users.access_log as al2
          where al2.user_id = al.user_id
            and al2.login_status = 0
            and al2.create_time::date = al.create_time::date
          order by al2.create_time::time ASC
         ) as t2
    ) as logout_time,
    al.create_time::date
from users.access_log as al
where al.user_id = ?;

出勤是根据日期排序,这很好,但我想将日期与月份名称一起排序 1月应该在底部,12月在顶部。

0 个答案:

没有答案