May 4, 2010 at 5:45 am
Hi,
I recently came across use of PARTITION BY with Aggregate functions. What I read I can use PARTITION BY clause with aggregate functions to more or less achieve similar result set as with using GROUP BY clause (probably event better).
So, I am trying to find out what is the difference between PARTITION BY and GROUP BY? And which one is better performance wise?
Regards,
Santosh
May 4, 2010 at 6:07 am
PARTITION BY is used in windowed aggregates, while GROUP BY is used in regular aggregates.
Look up OVER in BOL to find out more.
-- Gianluca Sartori
May 4, 2010 at 6:12 am
Better , in terms of performance , shouldn't enter into it as the do different things
GROUP by is for use by aggregate functions.
Ie
Select id,sum(costs)
from yourtab
group by Id
Partition by is for use with ranking functions
Select id,count(*) over (partition by id order by 1)
from yourtab
But a partition by can also be used in an aggregate function
Select id,sum(costs) over (partition by id )
from yourtab
May 4, 2010 at 6:24 am
Gianluca Sartori (5/4/2010)
PARTITION BY is used in windowed aggregates.
can you give any example ?
-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
May 4, 2010 at 6:27 am
Santosh Bandhu (5/4/2010)
What I read I can use PARTITION BY clause with aggregate functions to more or less achieve similar result set as with using GROUP BY clause (probably event better).
both work similarly there performance depend on kind of data/indexes used etc.
-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
May 4, 2010 at 6:47 am
Bhuvnesh (5/4/2010)
Gianluca Sartori (5/4/2010)
PARTITION BY is used in windowed aggregates.can you give any example ?
Dave put a neat example in his post, last query.
-- Gianluca Sartori
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy