我是来自以下查询的 2 个结果集,我想将结果“组合”到 1 个单个表中,但不知道如何从这里开始,请有人提供一些指导:
SELECT userid, vehicleId, count(vehicleId) As SearchCount FROM MemberSearches
GROUP BY userid, vehicleId
ORDER BY count(vehicleId) DESC
SELECT f.UserId, v.AutoId AS VehicleId, count(v.AutoId) AS SearchCount FROM Favorites f
LEFT JOIN [SellPost] sp
ON (f.PostId = sp.AutoId)
LEFT JOIN [Vehicle] v
ON (sp.CarId = v.AutoId)
GROUP BY f.UserId, v.AutoId
ORDER BY COUNT(v.AutoId) DESC
第一次选择的结果:
UserId VehicleId SearchCount
2926FC8A78FB 7 3
2926FC8A78FB 2 2
2926FC8A78FB 6 1
第二次选择的结果:
UserId VehicleId SearchCount
2926FC8A78FB 1 5
2926FC8A78FB 2 5
我需要达到最终结果:
UserId VehicleId SearchCount
2926FC8A78FB 1 5
2926FC8A78FB 2 7
2926FC8A78FB 6 1
2926FC8A78FB 7 3