c8574983ad90300f1cb73528d6398928fe4f4007
FAQ/Questions/Combining-Fields-with-Union.md
| ... | ... | @@ -0,0 +1,32 @@ |
| 1 | +#Combining Multiple Event Based Fields with UNION |
|
| 2 | + |
|
| 3 | +[[_TOC_]] |
|
| 4 | + |
|
| 5 | +##About |
|
| 6 | +Event-based or time-series data is often spread across multiple fields or data sources which makes it difficult to report on. The UNION operator may be used to combine these fields into one and create an artificial categorical field which defines the type of event it is. |
|
| 7 | + |
|
| 8 | +##Method 1 |
|
| 9 | + |
|
| 10 | +```sql |
|
| 11 | +CREATE VIEW EventView AS |
|
| 12 | +SELECT OrderDate AS Date, 'Order' AS Event, ShipCountry AS Country FROM |
|
| 13 | +Orders UNION |
|
| 14 | +SELECT ShippedDate AS Date, 'Shipment' AS Event, ShipCountry AS Country |
|
| 15 | +FROM Orders UNION |
|
| 16 | +SELECT HireDate AS Date, 'Hire' AS Event, Country AS Country |
|
| 17 | +FROM Employees |
|
| 18 | +``` |
|
| 19 | + |
|
| 20 | +##Method 2 |
|
| 21 | + |
|
| 22 | +Additionally, an outer query may be used to further simplify the results of the UNION |
|
| 23 | + |
|
| 24 | +```sql |
|
| 25 | +CREATE VIEW EventView AS |
|
| 26 | +SELECT DatePart(m,Date) as Month, DatePart(yyyy,Date) as YEAR, * FROM |
|
| 27 | +( |
|
| 28 | +SELECT OrderDate AS Date, 'Order' AS Event, ShipCountry AS Country FROM Orders UNION |
|
| 29 | +SELECT ShippedDate AS Date, 'Shipment' AS Event, ShipCountry AS Country FROM Orders UNION |
|
| 30 | +SELECT HireDate AS Date, 'Hire' AS Event, Country AS Country FROM Employees |
|
| 31 | +) AS IQ |
|
| 32 | +``` |
|
| ... | ... | \ No newline at end of file |
Integration.md
| ... | ... | @@ -1,32 +0,0 @@ |
| 1 | -#Combining Multiple Event Based Fields with UNION |
|
| 2 | - |
|
| 3 | -[[_TOC_]] |
|
| 4 | - |
|
| 5 | -##About |
|
| 6 | -Event-based or time-series data is often spread across multiple fields or data sources which makes it difficult to report on. The UNION operator may be used to combine these fields into one and create an artificial categorical field which defines the type of event it is. |
|
| 7 | - |
|
| 8 | -##Method 1 |
|
| 9 | - |
|
| 10 | -```sql |
|
| 11 | -CREATE VIEW EventView AS |
|
| 12 | -SELECT OrderDate AS Date, 'Order' AS Event, ShipCountry AS Country FROM |
|
| 13 | -Orders UNION |
|
| 14 | -SELECT ShippedDate AS Date, 'Shipment' AS Event, ShipCountry AS Country |
|
| 15 | -FROM Orders UNION |
|
| 16 | -SELECT HireDate AS Date, 'Hire' AS Event, Country AS Country |
|
| 17 | -FROM Employees |
|
| 18 | -``` |
|
| 19 | - |
|
| 20 | -##Method 2 |
|
| 21 | - |
|
| 22 | -Additionally, an outer query may be used to further simplify the results of the UNION |
|
| 23 | - |
|
| 24 | -```sql |
|
| 25 | -CREATE VIEW EventView AS |
|
| 26 | -SELECT DatePart(m,Date) as Month, DatePart(yyyy,Date) as YEAR, * FROM |
|
| 27 | -( |
|
| 28 | -SELECT OrderDate AS Date, 'Order' AS Event, ShipCountry AS Country FROM Orders UNION |
|
| 29 | -SELECT ShippedDate AS Date, 'Shipment' AS Event, ShipCountry AS Country FROM Orders UNION |
|
| 30 | -SELECT HireDate AS Date, 'Hire' AS Event, Country AS Country FROM Employees |
|
| 31 | -) AS IQ |
|
| 32 | -``` |
|
| ... | ... | \ No newline at end of file |