有一个表:
txn
号码 时间 金额
num time txnamt
8 20 100.00
8 21 50
8 22 30.
9 20 90
9 21 35
10 20 40
10 21 45
我想要的结果是:
号码 时间 金额
8 20 100.00
9 20 90
10 20 40
即每一个号码的在时间上的第一条记录
咋写??
select num time txnamt from txn 条件怎么写 ??
THANKS!!!
有的网友说
select distinct(num) time txnamt from txn order by num 行,其实不行的~~
txn
号码 时间 金额
num time txnamt
8 20 100.00
8 21 50
8 22 30.
9 20 90
9 21 35
10 20 40
10 21 45
我想要的结果是:
号码 时间 金额
8 20 100.00
9 20 90
10 20 40
即每一个号码的在时间上的第一条记录
咋写??
select num time txnamt from txn 条件怎么写 ??
THANKS!!!
有的网友说
select distinct(num) time txnamt from txn order by num 行,其实不行的~~
select num,min(ttime) as ttime from txn group by num)a,
(select * from txn)b
where a.num=b.num and a.ttime=b.ttime
where txn.num=a.num and txn.time=a.t
select num,min(ttime) as ttime from txn group by num)a,txn b
//这里这个可以换成 txn b 麻烦(select * from txn)b
where a.num=b.num and a.ttime=b.ttime