求一条SQL语句。
ID 餐别 时间
1 中餐 2009-10-25
2 中餐 2009-10-26
3 晚餐 2009-10-26
4 早餐 2009-10-27
结果
1 中餐 2009-10-25
3 晚餐 2009-10-26
4 早餐 2009-10-27
日期中有重复的。。我想一直得到最新的。。帮忙谢谢了
虽然对大家有些简单。但是有没有经典的算法呀。
这种问题在报表中总是出现。。
UP
SQL code:
select * from tb a where not exists(select 1 from tb where a.餐别=餐别 and a.时间<时间)
SQL code:
--> 测试数据: @T1
declare @T1 table (ID int,餐别 varchar(4),时间 datetime)
insert into @T1
select 1,'中餐','2009-10-25' union all
select 2,'中餐','2009-10-26' union all
select 3,'晚餐','2009-10-26' union all
select 4,'早餐','2009-10-27'
select * from @t1 a where not exists(select 1 from @t1 where a.餐别=餐别 and a.时间> 时间)
ID 餐别 时间
----------- ---- ------------------------------------------------------
1 中餐 2009-10-25 00:00:00.000
3 晚餐 2009-10-26 00:00:00.000
4 早餐 2009-10-27 00:00:00.000
(所影响的行数为 3 行)
3楼有点错误
SQL code
{{-
相关问答:
....接到一个小程序..工作原来大概是这样的...前台是WEB服务器.架构就是ASP+SQL..前台由ASP向SQL添加服务类别(表单).然后又后台程序读取表单..要实时读取..然后显示在服务器上面..从理论上面能行通不?如果可以..后台 ......
with adod_dict do
begin
close;
commandtext:='select bgqxcode,count(*) wjsl from wscl_wsda_file where wjnd=:tnd group by bgqxcode'; ......
求SQL语句优化工具?
针对SQL Server的
发送到我邮箱sclsmile@163.com
或者给我一个网址链接
关注。
http://www.net130.com/class/oracle_datum_soft/Embarcadero%20SQLTuner%202.0.2.rar
http://sp ......
data a b c d e tag
2009-11-01 11 ......