1SELECT * -- Total invoices per gender
2FROM (
3 SELECT invoice, gender
4 FROM sales
5) d
6PIVOT (
7 sum(invoice)
8 FOR gender IN ('F' AS "Women", 'M' AS "Men")
9);
10-- Table Sales:
11CREATE TABLE sales (
12 gender VARCHAR2(1 BYTE), -- 'F' or 'M'
13 invoice NUMBER
14);
1PIVOT
2 (SUM(TotalDue)
3 FOR Qyr
4 IN ([2013 Q1], [2013 Q2], [2013 Q3], [2013 Q4])
5 ) AS PivotTable
1SELECT SalesAgent AS PivotSalesAgent, India, US, UK FROM tblAgentsSales
2PIVOT
3(
4 SUM(SalesAmount) FOR SalesCountry IN (India, US, UK)
5)
6AS testPivotTable
7
8
9SELECT SalesAgent GrpBySalesAgent, SalesCountry, SUM(SalesAmount) Sales
10from tblAgentsSales
11GROUP BY SalesAgent, SalesCountry
12
13
14select SalesAgent TableSalesAgent, SalesCountry, SalesAmount
15from tblAgentsSales
1SELECT SalesAgent AS PivotSalesAgent, India, US, UK FROM tblAgentsSales
2PIVOT
3(
4 SUM(SalesAmount) FOR SalesCountry IN (India, US, UK)
5)
6AS testPivotTable
7
8
9SELECT SalesAgent GrpBySalesAgent, SalesCountry, SUM(SalesAmount) Sales from tblAgentsSales
10GROUP BY SalesAgent, SalesCountry
11
12
13select SalesAgent TableSalesAgent, SalesCountry, SalesAmount from tblAgentsSales