Log SQL query statements once

Source: Internet
Author: User

Previously found that more classic sentences, are recorded on the computer, I want to move to the blog today, in my opinion, blogging is really a very headache, it is the heart of a hurdle, I have to cross it.

1 CREATE TABLET_jeff (2Idint  not NULL,3Vinnumbervarchar(255)DEFAULT NULL,4Channelidvarchar(255)DEFAULT NULL,5   TimeStamp datetime DEFAULT NULL,6   PRIMARY KEY(ID)7 ) ;8 INSERT  intoT_jeffVALUES('1','Group3','3','2015-05-27 00:00:00');9 INSERT  intoT_jeffVALUES('2','Group2','5','2015-05-23 00:00:00');Ten INSERT  intoT_jeffVALUES('3','Group1','4','2015-05-25 00:00:00'); One INSERT  intoT_jeffVALUES('4','Group2','3','2015-05-29 00:00:00'); A INSERT  intoT_jeffVALUES('7','Group1','2','2015-05-30 00:00:00'); -  -  the SELECT *  fromT_jeff - --1, Vinnumber the same group of put together - --2. Sorting logic between groups: in reverse order of each group Channelid maximum value - --3, the group within the order: In accordance with channelid reverse.  +  - SELECTA.* +  from    [dbo].[T_jeff]A A         JOIN(SELECT   MAX([Channelid]) as [Maxchannelid] , at                         [Vinnumber] -                 from     [dbo].[T_jeff] -                GROUP  by [Vinnumber] -) B onA.vinnumber=B.vinnumber - ORDER  byB.maxchannelidDESC , -A.channelidDESC in          -          to         

Log SQL query statements once

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.