Answers for "pivot table"

SQL
5

pivot table

SELECT *        -- Total invoices per gender
FROM (
    SELECT invoice, gender
    FROM sales
) d
PIVOT (
    sum(invoice)
    FOR gender IN ('F' AS "Women", 'M' AS "Men")
);
-- Table Sales:
CREATE TABLE sales (
    gender VARCHAR2(1 BYTE),		-- 'F' or 'M'
    invoice NUMBER
);
Posted by: Guest on April-13-2021
1

create pivot table in sql

PIVOT
	(SUM(TotalDue)
	FOR Qyr 
    IN ([2013 Q1], [2013 Q2], [2013 Q3], [2013 Q4])
	) AS PivotTable
Posted by: Guest on June-25-2021
0

sql pivot table

select *
from
(
  select game, player, goals
  from yourtable
) src
pivot
(
  sum(goals)
  for player in ([John], [Paul], [Mark], [Luke])
) piv
order by game
Posted by: Guest on August-11-2021
0

pivot table sql

SELECT SalesAgent AS PivotSalesAgent, India, US, UK FROM tblAgentsSales
PIVOT 
(
	SUM(SalesAmount) FOR SalesCountry IN (India, US, UK)
)
AS testPivotTable


SELECT SalesAgent GrpBySalesAgent, SalesCountry, SUM(SalesAmount) Sales 
from tblAgentsSales 
GROUP BY SalesAgent, SalesCountry


select SalesAgent TableSalesAgent, SalesCountry, SalesAmount 
from tblAgentsSales
Posted by: Guest on February-04-2021
0

pivot table sql server

SELECT SalesAgent AS PivotSalesAgent, India, US, UK FROM tblAgentsSales
PIVOT 
(
	SUM(SalesAmount) FOR SalesCountry IN (India, US, UK)
)
AS testPivotTable


SELECT SalesAgent GrpBySalesAgent, SalesCountry, SUM(SalesAmount) Sales from tblAgentsSales 
GROUP BY SalesAgent, SalesCountry


select SalesAgent TableSalesAgent, SalesCountry, SalesAmount from tblAgentsSales
Posted by: Guest on February-04-2021
0

Pivot Table

SELECT * FROM   
(
    SELECT 
        category_name, 
        product_id
    FROM 
        production.products p
        INNER JOIN production.categories c 
            ON c.category_id = p.category_id
) t 
PIVOT(
    COUNT(product_id) 
    FOR category_name IN (
        [Children Bicycles], 
        [Comfort Bicycles], 
        [Cruisers Bicycles], 
        [Cyclocross Bicycles], 
        [Electric Bikes], 
        [Mountain Bikes], 
        [Road Bikes])
) AS pivot_table;
Code language: SQL (Structured Query Language) (sql)
Posted by: Guest on October-21-2021

Code answers related to "SQL"

Browse Popular Code Answers by Language