0

我有一个非常简单的问题让我很头疼。

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

在上表中,我想返回最早的日期custnumbrsopnumbe所以它看起来像这样

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.sopnumbein 组,它会出错。

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 回答