有三个表分别为tb1(产品资料),tb2(产品价格),tb3(公司信息),其中tb1.id=tb2.pid,tb1.user=tb3.user,tb1中有100万条数据,tb1中user有重复,tb2中pid无重复,tb3中user无重复。现在需要查询tb1中title包含字符“123”且user相同的只取按price desc,tb2.time,tb1.uptime desc排序后的第一条(即相同user只取一条),输出结果需要有tb1.id,company,title,price,uptime,phone,并按uptime desc,tb1.id desc 排序。请问怎样才能用一条语句快速查询出来?(SQL 2000)
tb1
------------
id user title uptime
tb2
------------
id pid price time
tb3
-------------
id user company phone
------解决方案--------------------
- SQL code
--5楼写错select a.id,c.company,a.title,b.price,a.uptime,c.phonefrom tb1 a join tb2 b on a.id = b.pid join tb3 c on a.[user] = c.[user]where a.title like '%123%' and a.id = (select top 1 t.id from tb1 t join tb2 e on t.id = e.pid where t.[user] = a.[user] order by e.price desc,e.[time],t.uptime desc)--try !
------解决方案--------------------