SQL ORDER BY date problem

后端 未结 10 1435
情歌与酒
情歌与酒 2020-11-30 05:14

Can you please help me in solving this problem. I am trying to order the results of an SQL query by date, but I\'m not getting the results I need.

The query I\'m usi

相关标签:
10条回答
  • this works for me:

    SELECT datefield FROM myTable ORDER BY CONVERT(DATE, datefield) ASC

    0 讨论(0)
  • 2020-11-30 06:07

    SELECT CONVERT(char(19), CAST(date AS datetime), 101) as [date]
    FROM tbemp ORDER BY convert(datetime, date, 101) ASC

    0 讨论(0)
  • 2020-11-30 06:07

    try this

    Order by Convert(datetime,@date) desc
    
    0 讨论(0)
  • 2020-11-30 06:12

    Following answer may help you

    perform your date ordering by your date identifier but use to_char() function in select clause and use some other identifier in select clause for date

    e.g.

    SELECT TO_CHAR(DISPDATE1,'DD/MM/YYYY') AS DISPDATE,
    SUM(APPLCOUNT) AS APPLIED,
    SUM(CONFCOUNT) AS CONFIRMED
    FROM
        (
            SELECT COUNT(ID) AS APPLCOUNT,
                       0 AS CONFCOUNT,
                       STUDENT.APPLIED_ON AS DISPDATE1
                FROM STUDENT
                WHERE STUDENT.ID = P_ID
                GROUP BY STUDENT.APPLIED_ON
            UNION
                SELECT 0 AS APPLCOUNT,
                       COUNT(ID) AS CONFCOUNT,
                       STUDENT.CONFIRMED_ON AS DISPDATE1
                FROM STUDENT
                WHERE STUDENT.ID = P_ID
                GROUP BY STUDENT.CONFIRMED_ON
        )
    GROUP BY DISPDATE1
    ORDER BY DISPDATE1;
    
    0 讨论(0)
提交回复
热议问题