关于一个很牛的SQL语句求教
769001 6商务双床套房469.0000228.00002007-02-01 17:35:30.060
769001 5商务大床套房469.0000228.00002007-02-01 17:34:23.107
code roomid
769001 4豪华标准房439.0000198.00002007-02-01 17:33:19.873
769001 3标准房409.0000148.00002007-02-01 17:32:15.890
769001 4豪华标准房409.0000198.00002007-02-01 17:31:13.793
769001 3标准房409.0000148.00002007-02-01 17:30:11.107
769001 2商务大床房389.0000188.00002007-02-01 17:24:53.093
769001 1大床房369.0000168.00002007-02-01 17:23:49.483
现在数据表是这样
我要取出唯一的ROOMID号 根据最大的时间选
[解决办法]
select top 1 roomid from table where code in (select distinct code from table) order by time desc
[解决办法]
select max(时间),roomid from table_test group by roomid
[解决办法]
你的数据得有个唯一ID,否则无法
[解决办法]
create table tb
(
Code int,
RoomID int,
RoomName nvarchar(128),
Price decimal(18,4),
CheckDate DateTime,
)
----借用Zine_Alone的表结构,语句如下:
select * from tb A where not exists (select 1 from tb where RoomID=A.RoomID and CheckDate> A.CheckDate)
[解决办法]
select * from tb A where not exists (select 1 from tb where RoomID=A.RoomID and CheckDate> A.CheckDate)
真没办法:上面语句,把两个 "tb "改成你的表名, "CheckDate "改成你的日期列名,就可以了.那儿用到临时表了?
[解决办法]
象这样的 只是取得所有的不唯一的ROOMID
也就是说可能存在多条相同时间的roomid是吗?
如果定义了 code的话 有的就取不到了
这句话什么意思?