0

我想写这样的东西

SELECT MIN(date),
       id 
   FROM test 
  WHERE t.SITE_ID=SITE_id 
  GROUP BY SITE_ID

但它不可能id通过呼叫获得一组后的 s。

然后我想出了这个

SELECT t.id 
  FROM test t 
 WHERE t.date IN(SELECT MIN(date) 
                   FROM test 
                  WHERE t.SITE_ID=SITE_id 
                  GROUP BY SITE_ID)

这个选择应该让我得到id与每个站点的最小日期相同日期的测试行的 s 是否有让它更简单?

4

2 回答 2

1

尝试

SELECT t1.id 
FROM test t1
inner join
(
   select site_id, min(date) as mdate
   from test
   GROUP BY site_id
) t2 on t1.site_id = t2.site_id and t1.date = t2.mdate
于 2013-09-04T06:52:10.953 回答
-2
SELECT t1.id 
FROM test t1
inner join
(
   select site_id, min(date) as mdate
   from test
   GROUP BY site_id, id
) t2 on t1.site_id = t2.site_id and t1.date = t2.mdate
于 2013-09-04T06:59:29.237 回答