I probably should have written this one first
Most of these are exactly the same as in SQL Server. There are a whole bunch of interesting analytic functions, most of which should look pretty familiar to anyone who has spent time querying SQL Server. Most, if not all, can be extended to be window functions, if you need per-group analysis of any kind.
Counting!
All of this works the same as in SQL Server.
SELECT COUNT(*), COUNT(COMMISSION_PCT), COUNT(DISTINCT COMMISSION_PCT) FROM HR.EMPLOYEES;
Oracle does have something kind of cool if you only need an approximate count of distinct values. Don’t ask me why there isn’t a similar function to get an approximate count of all values. I wasn’t invited to that meeting. This is good for really large data sets where you just need a rough of idea of the values you’re working with.
SELECT APPROX_COUNT_DISTINCT(COMMISSION_PCT) FROM HR.EMPLOYEES;
Sums and Averages
Fun fact: under the covers, AVG is just a SUM and a COUNT anyway.
--SUM and COUNT SELECT JOB_ID, SUM(SALARY) AS "DEPT_TOTAL", COUNT(JOB_ID) AS "POSITIONS", (SUM(SALARY) / COUNT(JOB_ID)) * .100 AS "AVG_SALARY" FROM HR.EMPLOYEES GROUP BY JOB_ID ORDER BY DEPT_TOTAL DESC; --AVG is a little easier SELECT JOB_ID, SUM(SALARY) AS "DEPT_TOTAL", COUNT(JOB_ID) AS "POSITIONS", AVG(SALARY) * .100 AS "AVG_SALARY" FROM HR.EMPLOYEES GROUP BY JOB_ID ORDER BY DEPT_TOTAL DESC;
The Max for the Minimum
You also have your MIN and MAX functions, along with the HAVING clause, to filter aggregates.
SELECT JOB_ID, MIN(SALARY), MAX(SALARY) FROM HR.EMPLOYEES GROUP BY JOB_ID HAVING MIN(SALARY) > 10000 ORDER BY JOB_ID;
Something not boring
The LISTAGG function is something I’d absolutely love to have something like in SQL Server. It takes column values and gives you a list per row, delimited by the character of your choice. It’s pretty sweet, and the syntax is a lot easier to bang out than all the XML mumbo jumbo in SQL Server.
SELECT JOB_ID, LISTAGG(EMPLOYEE_ID, ', ') WITHIN GROUP (ORDER BY EMPLOYEE_ID) AS "EMPLOYEE_IDS" FROM HR.EMPLOYEES GROUP BY JOB_ID ORDER BY JOB_ID;

And the puppies is staying, yo!
For reference, to do something similar in SQL Server, you need to do this:
SELECT [e].[JobTitle] , STUFF(( SELECT ', ' + CAST([e1].[BusinessEntityID] AS VARCHAR) FROM [HumanResources].[Employee] AS [e1] WHERE [e1].[JobTitle] = [e].[JobTitle] FOR XML PATH('') ), 1, 2, '') AS [EMPLOYEE_IDS] FROM [HumanResources].[Employee] AS [e] GROUP BY [e].[JobTitle];
Good luck remembering that!
SQL is a portable skill
Once you have the basics nailed down, and good fundamentals, working with other platforms becomes less painful. In some cases, going back is the hardest part! My knowledge of Oracle is still very entry level, but it gets easier and easier to navigate things as I go along. I figure if I keep this up, someday I’ll be blogging from my very own space station.
Thanks for reading!
Wanna learn from us, but can't travel? Our in-person classes now have online dates, too.