0

私は非常に単純な質問をしていますが、それは私のお尻を蹴っています。

CUSTNMBR   |  first_date |  SOPNUMBE
----------------------------------------
3344771005 |  2012-05-03 |  334471961748         
3344771005 |  2012-04-04 |  334476873726

custnumbr上の表では、最も早い日付と一緒に返したいので、次のsopnumbeようになります

3344771005 |  2012-04-04 |  334476873726

私はこれを使いました

Select a.CUSTNMBR, min(a.Tax_Date) as first_date, a.SOPNUMBE
from SOP30200 as a
where a.CUSTNMBR = '3344771005'
Group by a.CUSTNMBR, a.SOPNUMBE

しかし、それはすべての変数を返し、グループ内をノックオフするa.sopnumbeとエラーになります。

4

2 に答える 2

2

これを試して:

Select top 1 a.CUSTNMBR, a.Tax_Date as first_date, a.SOPNUMBE 
from SOP30200 as a 
where a.CUSTNMBR = '3344771005' 
order by a.Tax_Date asc
于 2012-05-16T16:48:00.280 に答える
0

試す

Select TOP 1 a.CUSTNMBR, min(a.Tax_Date)as first_date, a.SOPNUMBE
from SOP30200 as a
where a.CUSTNMBR = '3344771005'
Group by a.CUSTNMBR, a.SOPNUMBE'
ORDER BY 2 ASC
于 2012-05-16T16:46:27.967 に答える