Ask SQL SERVER to extract the latest records according to the specified conditions.

there is a system that has no source code and cannot find a developer. Now I want to make a report by myself, but I have encountered a disgusting problem. Consult
database SQL SERVER 2008 R2
the simplified table structure is as follows
id customer ID purchase date due time commodity ID unit price
1 1 2017-1 2018-3-1 3 12 2
2 1 2018-5-1 2019-6-13 13 3
3 3 2016-3-15 2017-2-18 14
4 3 2017-3-15 2018-1-18 15 5
5 3 2018-2-1 2018-6-1 9 16 6
6 3 2018-7-1 2018-6-9-17-7
7 4 2015-4 2016-12-2015 18 8
8 4 2016-12-21 2017-5-4 15 19
9 4 2017-5 -5 2017-12-31 15 1 10 10
10 4 2018-6-1 2020-1-1 15 1 11 11

clipboard.png

ID
:

id ID ID
2 1 2018-5-1 2019-6-1 3 1 3 3
4 3 2017-3-15 2018-1-1 8 1 5 5
6 3 2018-7-1 2018-6-1 9 -1 7 -7
10 4 2018-6-1 2020-1-1 15 1 11 11

clipboard.png


//:
// Table_Bill

,


id  |  ID  |    |    |  ID  |    |    |  

Id  |  CusId   |  BuyTime  |  DueTime  | ArticlId |  Num   | Price |  Money

,

SELECT a.*  FROM [Table_Bill] a,(SELECT MAX(BuyTime) AS BuyTime ,ArticlId FROM [Table_Bill] GROUP BY ArticlId) b

WHERE a.BuyTime=b.BuyTime AND a.ArticlId=b.ArticlId 

ORDER BY a.ArticlId

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e510e4-4d49a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e510e4-4d49a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?