Skip to content

Instantly share code, notes, and snippets.

@radityopw
Created February 29, 2016 07:31
Show Gist options
  • Save radityopw/5a63dcd35f997bb626d1 to your computer and use it in GitHub Desktop.
Save radityopw/5a63dcd35f997bb626d1 to your computer and use it in GitHub Desktop.
use AdventureWorks2012
go
WITH Sales_CTE
AS
(
SELECT SalesPersonID, COUNT(*) as JML_ORDER
FROM Sales.SalesOrderHeader
WHERE SalesPersonID IS NOT NULL
GROUP BY SalesPersonID
),
avg_sales_CTE
as (
SELECT AVG(JML_ORDER) AS rata_order
from sales_cte
)
select *
FROM Sales_CTE
where jml_order > (select rata_order from avg_sales_CTE);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment