辛苦的成果啊 select distinct date format convert

    技术2022-06-12  51

     

    SELECT        CONVERT(Varchar(10), dateRecorded, 103) AS dateRecorded

    FROM            (SELECT DISTINCT CONVERT(DATETIME, CONVERT(Varchar(10), cs.dateRecorded, 103)) AS dateRecorded

                              FROM            Components AS c INNER JOIN

                                                        ComponentStatus AS cs ON c.component_id = cs.component_id

                              WHERE        (c.machine_id = 10)) AS A

    ORDER BY dateRecorded DESC

     

     

    -------------------------

     

    SELECT        CONVERT(varchar, dateRecorded, 103) AS dateRecorded

    FROM            (SELECT DISTINCT CONVERT(DATETIME, CONVERT(varchar, cs.dateRecorded, 101),101) AS dateRecorded

                              FROM            Components AS c INNER JOIN

                                                        ComponentStatus AS cs ON c.component_id = cs.component_id

                              WHERE        (c.machine_id = 10)) AS A

    ORDER BY dateRecorded DESC

    -----------------------------------------

     

    SELECT        CONVERT(varchar, dateRecorded, 103) AS dateRecorded2

    FROM            (SELECT DISTINCT CONVERT(DATETIME, CONVERT(varchar, cs.dateRecorded, 103),103) AS dateRecorded

                              FROM            Components AS c INNER JOIN

                                                        ComponentStatus AS cs ON c.component_id = cs.component_id

                              WHERE        (c.machine_id = 10)) AS A

    ORDER BY dateRecorded  DESC

     

     

    ------------------------------------------------

    第三个是成功的,但是不好的地方在于column的名字改变了;

    而如果不改变名字,就没办法排序了,shit!

     


    最新回复(0)