我需要重新构建以下查询,以便改善性能和时间
考虑我的表格是录音和用户
录音表
bid | Date
1 | 02/10/2016 14:15:23
1 | 02/10/2016 10.30.15
1 | 02/09/2016 16.10.45
2 | 02/15/2016 14:15:23
2 | 01/10/2016 10.30.15
2 | 01/09/2016 16.10.45
用户表
id | Udate | Name
1 | 02/10/2016 15:15:23 | Bill
2 | 02/15/2016 14:15:23 | Max
我的要求是加入2个表格和
select max(date) from Recordings table group by bid with max(date)>udate
select distinct bid from Recordings ,users
where Recordings.bid =users.id group by bid having max(date)>udate
由于
答案 0 :(得分:0)
我不确定这一点,你的目的不客观。
SELECT bid, date , udate, name FROM Recordings
JOIN users on users.id = Recordings.bid
WHERE max(Recordings.udate) > users.date
GROUP BY bid
如果您有超过10000条更改记录,您还可以关注 RECOMPILE 提示
答案 1 :(得分:0)
我认为你正在寻找这样的东西:
SELECT id, uDate, name
FROM users
INNER JOIN
(
SELECT bId, MAX(Date) as uDate
FROM Recordings
GROUP BY bId
) x ON id = bId