Thursday 26 March 2020

SQL Queries examples for SQL Developer

In this blog shared SQL queries with explanation, different  syntax and use cases.
1 -- show the number of employees who started in the same month as the employee in the row. 
We will need to narrow or restrict the count to just that month for each row. We use the window PARTITION clause, like so:
SELECT COUNT(*) OVER (PARTITION BY MONTH(date_started),YEAR(date_started)) 
As NumPerMonth, 
DATENAME(month,date_started)+' '+DATENAME(year,date_started) As TheMonth,
firstname, lastname
FROM Employee
ORDER BY date_started;


Partitions allow you to filter the window into sections by a certain value or values. Each section is often called the window frame.



2 -- let’s say we not only wanted to find out how many
 employees started in the same month, but we want to show 
in which order they started that month. 



SELECT COUNT(*) OVER (PARTITION BY MONTH(date_started), YEAR(date_started) 
ORDER BY date_started) As NumThisMonth,
    DATENAME(month,date_started)+' '+DATENAME(year,date_started) As TheMonth,
    firstname, lastname, date_started
FROM Employee
ORDER BY date_started;


In this case, ORDER BY modifies the window so that it goes from the start of the partition (in this case the month and year of when the employee started) to the current row. 
Thus, the count restarts at each partition.




Oracle to SQL Server and SQL Server to Oracle Migration Guide

In this blog, I shared some link  which will helpful to understand and implement these migration.

Thanks to all author those share knowledge.


Links :- 

https://www.toptal.com/sql/oracle-sql-server-differences
https://www.toptal.com/sql/oracle-sql-server-migrations-pt-2
https://www.toptal.com/sql/oracle-sql-server-migrations-pt-3