这个SELECT语句不会写?
数据表:Table1
字段: HideNO CreatDate
20055 2007-01-04 08:10:20
20055 2007-01-04 09:10:20
20055 2007-01-05 08:10:20
20023 2007-01-07 10:10:20
20023 2007-01-03 08:10:20
.... ......
最后想得到结果为:
字段: HideNO CreatDate
20055 2007-01-04 08:10:20
20023 2007-01-07 10:10:20
..... ...............
这个Select 语句怎么写?
[解决办法]
select HideNO , min(CreatDate) as CreatDate
from Table1
group by HideNO
[解决办法]
SELECT HideNO,MIN(CreatDate) FROM Table1 GROUP BY HideNO
[解决办法]
Select HideNO,MIN(CreatDate) From Table1 Group By HideNO
[解决办法]
select * from Table1 t where table1.createdate =(select min(createdate) from table1 where hideNO=t.hideno)
这样写的好处是便于扩展
也就是如果你是HIDEID,还有其他字段来决定我想要的最新时间的话
这个就有优势了
[解决办法]
数据表:Table1
字段: HideNO CreatDate
20055 2007-01-04 08:10:20
20055 2007-01-04 09:10:20
20055 2007-01-05 08:10:20
20023 2007-01-07 10:10:20
20023 2007-01-03 08:10:20
.... ......
最后想得到结果为:
字段: HideNO CreatDate
20055 2007-01-04 08:10:20
20023 2007-01-07 10:10:20 ------这一句
..... ...............
结果有些问题
道底是要最近时间,还是最晚时间
select HideNO , min(CreatDate) as CreatDate
from Table1
group by HideNo
执行的结果是
HideNO CreatDate
-------------------------------------------------- -----------------------
20023 2007-01-03 08:10:20.000
20055 2007-01-04 08:10:20.000
(2 行受影响)
select HideNO , max(CreatDate) as CreatDate
from Table1
group by HideNo
执行的结果是
HideNO CreatDate
-------------------------------------------------- -----------------------
20023 2007-01-07 10:10:20.000
20055 2007-01-05 08:10:20.000
不知道楼主的答案是如何得到
[解决办法]
不是也一样,取得最小值;
select HideNO , min(CreatDate) as CreatDate
from Table1
group by HideNO