I am doing a query where I need to strip out some lower-level results using the Max command in SQL Server. How can I then make a higher level Group By statement? I know I can use a temp table for this. I expect high volume and want to avoid creating and destroying the temp table for performance purposes.
SELECT k.Result_ID, k.Key_Name, max(k.Value_Percentage) as Percentage
FROM Key_Word k
LEFT JOIN Phrase p
ON p.Result_ID = k.Result_ID
AND p.Key_Name = k.Key_Name
AND k.Phrase_Flag = 1
AND @fulltextsearch LIKE '%' + p.phrase + '%'
WHERE k.Key_Word IN
('estimated', 'flow', 'cash', 'approximate', 'brian', 'go', 'store')
AND (k.Phrase_Flag = 0 OR p.Phrase IS NOT NULL)
GROUP BY k.Result_ID, k.Key_Name
ORDER BY k.Result_ID ASC;
Thanks for your help.
Are you looking for HAVING ?:
Or if you need to you want to show
max(k.Value_Percentage)per Result_ID , you canuse
WITH ROLLUP