SQL “Dummy” Table, CTE and Pivot — Simple Example

Create virtual “dummy” Table, for testing something in stydying process, you can make like this:

Dummy table name is earthquackes and columns is cDate and Magnitude.

For using one table many times use temporary table function

;WITH - CTE common table expression

CTE Table

;WITH tablename as ( 0any select script select * from -) select * from tablename

u can also use convert function in last select convert(DATE, CTEearthquakes.cDate) as fDate

also, you can use CTE temporary tables many times by this ;WITH statement:

and in last select you can use all temporary tables, wich was created above, for example
make union from temporary tables, or join etc.

please see every steps of codes in my github: