表名为:MZGH,
字段为 BRID , sj
663978 2012-03-21 9:36:21
664049 2012-03-21 8:57:43
664049 2012-03-21 9:00:39
664055 2012-03-21 8:17:03
664055 2012-03-21 8:18:53
664055 2012-03-21 8:22:34
664234 2012-03-21 10:25:40
664234 2012-03-21 10:48:33
664623 2012-03-21 8:14:51
664623 2012-03-21 8:14:52
664623 2012-03-21 8:14:52
665413 2012-03-21 10:17:51
665413 2012-03-21 10:25:49
666198 2012-03-21 15:20:20
666198 2012-03-21 15:23:47
666268 2012-03-21 15:14:26
666268 2012-03-21 15:15:13
666268 2012-03-21 15:16:58
666268 2012-03-21 15:19:20
每个BRID,只需取 时间最小的 一行记录 ,
如何写语句?
字段为 BRID , sj
663978 2012-03-21 9:36:21
664049 2012-03-21 8:57:43
664049 2012-03-21 9:00:39
664055 2012-03-21 8:17:03
664055 2012-03-21 8:18:53
664055 2012-03-21 8:22:34
664234 2012-03-21 10:25:40
664234 2012-03-21 10:48:33
664623 2012-03-21 8:14:51
664623 2012-03-21 8:14:52
664623 2012-03-21 8:14:52
665413 2012-03-21 10:17:51
665413 2012-03-21 10:25:49
666198 2012-03-21 15:20:20
666198 2012-03-21 15:23:47
666268 2012-03-21 15:14:26
666268 2012-03-21 15:15:13
666268 2012-03-21 15:16:58
666268 2012-03-21 15:19:20
每个BRID,只需取 时间最小的 一行记录 ,
如何写语句?
from MZGH
group by BRID
select brid , min(sj) sj from mzgh group by brid--如果有多个字段
select t.* from mzgh t where sj = (select min(sj) from mzgh where bird = t.bird )
select t.* from mzgh t where not exists (select 1 from mzgh where bird = t.bird and sj < t.sj)
from MZGH
group by BRID
group by BRAID
select BRID,min(sj) from MZGH group by BRID