求一条 SQL 语句
发布网友
发布时间:2022-04-22 09:46
我来回答
共9个回答
热心网友
时间:2022-04-09 22:35
查询最后一次修理的清单:
SELECT 设备编号,MAX(修理时间) FROM Table1 GROYP BY 1
查询这些修理记录中,修理费大于100的:
SELECT * FROM Table1 WHERE 修理费>100 AND
设备编号&修理时间 (SELECT 设备编号&MAX(修理时间) FROM Table1 GROYP BY 1)
热心网友
时间:2022-04-09 23:53
Select top1 * from Table1 where Mfy>100 order by TM desc
热心网友
时间:2022-04-10 01:28
select * from Table1 t1 where t1.Mfy>100 and t1.TM >all(select TM from Table t2 where t2.ID=t1.ID)
热心网友
时间:2022-04-10 03:19
1楼,3楼,5楼,6楼的,看一眼就知道不行
-------------------
ORACLE下测试,可通过
select * from Table1 a where a.id=(select b.id from Table2 b where a.id=b.id and b.Mfy>100 and rownum=1 order by TM desc)
不行再问我。
热心网友
时间:2022-04-10 05:27
特别推荐:
select * from table1 where mnr in (select mnr from (
select TM ,max(Mnr ) mnr from table1 where mry > 100 group by TM ))
热心网友
时间:2022-04-10 07:52
可以用下面的sql语句实现(用内连接就可以实现了)
select t.ID , t.TM ,Mnr,Mfy,Mry
from Table1 as t
inner join
(select ID,max(TM) from Table1 where Mfy>100 group by ID) as e
on t.ID=e.ID
热心网友
时间:2022-04-10 10:33
select * from Table1 where Mfy>100
热心网友
时间:2022-04-10 13:31
数据库什么版本的?
sql2005、sql2008、sql2000还是oracle?
sql2005、sql2008、oracle:
select ID,TM,Mnr,Mfy,Mry from
(
select a.*,row_number() over (partition by ID order by a.TM desc) rn
from
(select * from table1 where Mfy > 100) a
) aa
where aa.rn=1;
sql2000:
参考其他同学的吧。
热心网友
时间:2022-04-10 16:46
select A.*from Table1 as A , (select ID,max(TM)from Table1 group by ID) B where A.ID=B.ID and A.TM=B.TM and B.Mfy>100