OVER Clause + Aggregate


Hoje estava estudando para certificação 70-433 descobri algo que desconhecia até então, é possivel fazer uma soma “SUM”, média “AVG”, etc sobre um conjunto ou subconjunto de registros… Melhor ver na pratica…

SELECT
	[database_id]
	,[name]
	,[compatibility_level]
	,COUNT(*) OVER() as [QTD_TOTAL_DATABASES]
	,COUNT(*) OVER(partition by [compatibility_level]) as [QTD_TOTAL_DATABASES_DO_MESMO_COMPLEVEL]
FROM SYS.databases
ORDER BY [database_id]




REF: http://msdn.microsoft.com/en-us/library/ms189461.aspx
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s