Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
mruprai
Starting Member
12 Posts |
Posted - 2012-10-29 : 09:00:07
|
using sql serverhere is what i haveSELECT FilmParticipation.PartType, COUNT(*) FROM FilmParticipationGROUP BY FilmParticipation.PartType;however is there a more effcient way in SQL server 2008 using over? |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-10-29 : 09:45:53
|
quote: Originally posted by bandi First open NewEditor in SSMS, then press ctrl+M (for getting execution plan along with query results)-- Check this linkhttp://blog.sqlauthority.com/2007/08/28/sql-server-actual-execution-plan-vs-estimated-execution-plan/Run following queries at a time:SELECT PartType, COUNT(*) over(partition by PartType) FROM FilmParticipationGOSELECT PartType, COUNT(*) FROM FilmParticipation GROUP BY PartTypeGOYou can see the cost of the operation (2nd one will take less cost)--Chandu
trhe above two queries are not equivalentfirst one gives details along with count value added to each of detail row whereas second query gives aggregated result alonethe equivalent query using OVER would be likeSELECT DISTINCT PartType, COUNT(*) over(partition by PartType) FROM FilmParticipation ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|