How do I take the last record in a table's grouping?

Source: Internet
Author: User

SELECT a. Truckorder,a. AddrType ,a. Opeaterby ,c. Deptname,         b Driver+ + (varchar ( 16e . opeaterdt , 121) as  dopeaterdt         b Driver+ + (varchar ( 16f . opeaterdt , 121) as  copeaterdt         b Driver+ + (varchar ( 16g . opeaterdt , 121) as  lopeaterdt         b Driver+ + (varchar ( 16h . opeaterdt , 121) as  hopeaterdt         b Driver b Transtype,convert ( varchar ( 16), b . truckdt , 121) as  truckdt b Truckno b Truckmodel Into #TruckWay From dbo. T_truckway as a         join  dbo T_truckorder  as  b  on  a Truckorder= b Truckorder  and  b. Cfmflag= Y '  and  b Auctionstatus= Y ' JOIN bas_department as C on b. Deptcode=c. Deptcode JOIN (SELECT truckorder,MAX(Opeaterdt) as Opeaterdt fromT_truckwayGROUP bytruckorder) asD ona. Truckorder=d. Truckorder and a. Opeaterdt=d. OpeaterdtLeft joins t_truckway as e on a. Truckorder=e. Truckorder and e. AddrType=3        left  join  t_truckway  as  on  a Truckorder= f Truckorder  and  f. Addrtype= 4         left  join  t_truckway  as  on  a Truckorder= g Truckorder  and  g. Addrtype= 5         left  join  t_truckway  as  on  a Truckorder= h Truckorder  and  h. Addrtype= 6 SELECT * from #TruckWay SELECT COUNT(1) as total from #Truck the

From for notes (Wiz)

How do I take the last record in a table's grouping?

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.