Search
 
SCRIPT & CODE EXAMPLE
 

SQL

pivot

/****** Script for SelectTopNRows command from SSMS  ******/
SELECT *,isnull(pvt1.id,0) FROM(
SELECT id,date,relay_type,line_number,machine_number
,process,TIMES,time_val
FROM 
[OutputMonitoring].[dbo].[output_tbl] 

UNPIVOT(
time_val FOR times
IN
([0000HR],
 [0100HR])
) AS PV1

WHERE machine_number = 'CVR 9' and date = '2022-07-14'

)tb2

PIVOT (
    max(time_val)
    FOR TIMES IN ([0000HR],
 [0100HR])
)pvt1

FULL JOIN target_tbl
on
target_tbl.relay_type = pvt1.relay_type 
and target_tbl.line_no = pvt1.line_number
and target_tbl.machine_count = pvt1.machine_number
and target_tbl.process = pvt1.process
and target_tbl.Date = pvt1.date
WHERE pvt1.date = '2022-07-14'
Comment

PREVIOUS NEXT
Code Example
Sql :: athena create table 
Sql :: how insert auto increment 
Sql :: sql datitime to date 
Sql :: postgres trigger insert into another table 
Sql :: sql get first letter of string 
Sql :: uppercase sql 
Sql :: update table mysql 
Sql :: update in sql server table 
Sql :: mysql connectiion timeout 
Sql :: all tables and views oracle 
Sql :: sql oracle update multiple rows 
Sql :: install mysql 5.7 ubuntu 20.04 
Sql :: create empty table from existing table 
Sql :: change permission to database mysql 
Sql :: psql select * from table 
Sql :: select last n rows mysql 
Sql :: postgres create database if not exists 
Sql :: SQL SELECT DISTINCT Statement 
Sql :: mysql timezone 
Sql :: insert query in sql 
Sql :: replace tab in sql 
Sql :: postgre query date 
Sql :: Grant privileges of databse to user 
Sql :: call function in query sql server 
Sql :: mysql show category once count how many products 
Sql :: how to start my sql server on mac 
Sql :: sqlite unix timestamp 
Sql :: sql select most frequent value in group 
Sql :: sql set data from a select query to a temp table and insert 
Sql :: copy from one table to another postgres using matching column 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =