Search
 
SCRIPT & CODE EXAMPLE
 

SQL

pivot in sql

SELECT <non-pivoted column>,  
    [first pivoted column] AS <column name>,  
    [second pivoted column] AS <column name>,  
    ...  
    [last pivoted column] AS <column name>  
FROM  
    (<SELECT query that produces the data>)   
    AS <alias for the source query>  
PIVOT  
(  
    <aggregation function>(<column being aggregated>)  
FOR   
[<column that contains the values that will become column headers>]   
    IN ( [first pivoted column], [second pivoted column],  
    ... [last pivoted column])  
) AS <alias for the pivot table>  
<optional ORDER BY clause>;
Comment

sql pivot

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
);
Comment

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
Comment

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
Comment

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
Comment

pivot and unpivot in sql

SELECT * FROM(
SELECT date,line_number,machine_number,TIME,VAL FROM(
select *
from output_tbl 
unpivot
(
  VAL
  for TIME in ([0000HR])
) uvt

)tb1 )tb3
PIVOT (
    max(VAL)
    FOR TIME IN ([0000HR])
)pvt

Comment

PREVIOUS NEXT
Code Example
Sql :: how-to-remove-mysql-root-password 
Sql :: on sql table data exists 
Sql :: oracle grant directory 
Sql :: mysql delete from where like 
Sql :: using distinct and count together in sql 
Sql :: sql mode 
Sql :: php5-mysql has no installation candidate 
Sql :: 1422: Explicit or implicit commit is not allowed in stored function or trigger 
Sql :: return the number of records in a single table mysql 
Sql :: not between mysql 
Sql :: sql composite key 
Sql :: how to find max and min salary in sql 
Sql :: inner join mysql 
Sql :: sql query to return field name of a table 
Sql :: SQL Query to delete all the tables in a database 
Sql :: sql server python connection 
Sql :: how to generate ids in sql 
Sql :: difference between in and between in sql 
Sql :: delete insert record in sql server 
Sql :: mysql query where in select 
Sql :: mysql date time string format for marshmellow field schema 
Sql :: sum row in sql 
Sql :: what is delete in sql 
Sql :: get comma separated values in mysql with group by 
Sql :: sqlplus change user 
Sql :: Host ' is not allowed to connect to this MySQL server 
Sql :: postgres meta command to show all rows in table 
Sql :: delete from table where length sql 
Sql :: truncate table sql server foreign key 
Sql :: sql average 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =