Skip to main content

Questions tagged [pivot]

A pivot (or crosstab) converts row data into columnar data, and vice versa for an unpivot. Not all databases support explicit PIVOT syntax but the functionality can be implemented, often using decision logic (CASE statements, etc), aggregate functions, or an extension.

Filter by
Sorted by
Tagged with
-1 votes
1 answer
55 views

Pivot to three named columns

Students may have more than one race.I want to add races to report with new headings: Race1, Race2 and Race3 only. select s.lastfirst, s.grade_level, max(case when sr.racecd = 100 then 100 else 0 end)...
ronbo760's user avatar
-1 votes
1 answer
391 views

Using different aggregate functions in a pivot

I have a table of data collected in the time as shown below. I would pivot them using different aggregate functions: average for C1 and sum for the others. How could I achieve it ? DECLARE @T AS ...
Alley's user avatar
  • 9
-1 votes
1 answer
46 views

Pivoting 2 columns into a rows

I hope one can help me with this issue, I have a list of personnel and each one of them have same/different skills I need someone to help me to create a SQL script to change it I have these two ...
Cuauhtemoc's user avatar
-1 votes
1 answer
28 views

Need to get results grouped by fields and column value as name

I have table as below reported_date url stautus_code country 2022-01-20 example.com 200 India 2022-02-29 example.com 200 US 2022-01-20 example.com 200 France 2022-01-20 sample.com 200 India 2022-...
santosh's user avatar
  • 99
-1 votes
1 answer
74 views

Combining multiple rows into one row

I’ve used the following SQL query to pull out the following data: Select Employee_Department, Employee_ID, DateTime_From, Wage_From, DateTime_To, Wage_To From wage_tbl Where Employee_ID = 254 or ...
user1553584's user avatar
-1 votes
1 answer
82 views

Pivoting date data [duplicate]

How to join all different rows with the same ID but a different DATE and return it as a unique row with new columns like DATE_0, DATE_1, DATE_2, ...? Consider this table: +----+------------+ | ID | ...
Tomay's user avatar
  • 21
-1 votes
1 answer
280 views

I want to transpose Column values into Row of Specific values like 'GType'(values as rows) as mentioned in the below example

Example Table: Result Table: I want to transpose Column into Rows of Specific Row values like 'GType'(values) as mentioned in the below example. I want a results to be in the below example format. ...
Vishal Thapa's user avatar
-1 votes
1 answer
32 views

Pivot and Insert

I have two tables. One is like this The other is like this How can I use one MySQL query to insert all users subject, total scores of those terms to table two. I have manage to insert only first ...
SAIFULLAHI SULAIMAN's user avatar
-1 votes
1 answer
818 views

How to do looping and use case when logic from dynamicaly variable in mysql

I'm new in mysql Before I have question and have the answer from someone. But I need a improve again from the query. This is my sampling data on mysql db table test With this query on below from ...
epm.007's user avatar
  • 29
-1 votes
1 answer
671 views

count record according to month for all user need mysql query

I have 2 tables: user id username 1 a 2 b transaction id user_id transaction_date 1 1 2016-02-02 11:23:02 2 1 2016-03-02 11:23:02 3 2 2016-02-02 11:23:02 I want ...
abhayendra's user avatar
-1 votes
1 answer
36 views

Sql Server 2014 - Rows to Columns convert Dynamically- [duplicate]

Below are my query and table details create table #ReviewData ( ProjectId int, ReviewId int, ReviewDataPointKey varchar(max), ReviewDataPointValue varchar(max)) Insert into #ReviewData values (...
Mahi's user avatar
  • 11
-2 votes
2 answers
2k views

Turning columns result set into independant rows in MySQL

I am pretty new to this and have been struggling over one issue. I have a result set which for each Opportunity in a table (id as primary key), provides a date for a first cashflow (DFCFW) as a column ...
FredK Trashmail's user avatar
-2 votes
1 answer
1k views

Trying to combine multiple rows into one row with different values [closed]

I have a table that looks like the following: item_code | whse_desc | Height | Width | Window -------------------------------------------------- WD123 | KC | 1.25 | 4.25 | 1 WD123 | ...
dstanton's user avatar
-2 votes
2 answers
74 views

Insert data from one table to another

I have a table in which new entries come in every second. The table is just like this: value1 data1 Value2 data2 1 Er 2 Er 3 Er 4 Er Now insert these value in other table as Value data 1 Er 2 ...
charu gupta's user avatar
-2 votes
1 answer
576 views

crosstab dynamic in mysql

this is output from query true like this: bln bt cl kj ma pj sb sn st wh 1 421 465 437 474 196 29 146 392 37 2 398 443 328 462 181 0 30 438 0 3 209 258 105 298 51 0 0 213 0 ...
beni pr's user avatar
  • 11
-2 votes
1 answer
435 views

How to get one column and select other column as horizontally

Given data of the form... +-------------+--------------+ | Employee_ID | Candidate_ID | +-------------+--------------+ | 1000 | 1 | | 1000 | 2 | | 1000 | 5 ...
WD_Apps's user avatar
-2 votes
1 answer
55 views

How link data - delimiter

How can I make script take mydata from mytable instead of providing values like in an example below? SO instead of set values to Code and Location link these to mycolumns in mytables? with data as ( ...
Julija Ivanovica's user avatar
-2 votes
2 answers
222 views

Convert rows to columns in SQL [duplicate]

I'm looking for a query to achieve the following: Current table format user_id meta_key meta_value ------- -------- ---------- 1 address1 abc street 1 city ...
Jose Salazar's user avatar
-3 votes
1 answer
503 views

How to display multiple columns as rows + columns [closed]

I have this table and data: CREATE TABLE #t1 ( [Year] int, Student int, Test char(2), Score int, Achievement varchar(32) ); INSERT #t1 VALUES (2014,1,'MA',697, '...
il.king's user avatar
-3 votes
1 answer
2k views

Sql server Pivot, Joining 4 tables and Group By

I am trying to produce the following: Product Name | Color | 40 | 41 | 42 | 43 | 44 | -----------: | ------|---:|--: |--: |---:|---:| COOL99-3 | Black | 70 | 1 | 71 | 16 | 30 | COOL99-3 | ...
NaSeEr's user avatar
  • 1
-3 votes
1 answer
40 views

Reformatting Date with Pivot or Unpivot [closed]

I'm struggling trying to covert the format of a table with the following fields: Customer|Fiscal Year| September Amount| October Amount|November Amount|... to: Customer|Fiscal Year|Month|Amount I'...
Andy Donnelly's user avatar
-3 votes
1 answer
67 views

two columns in two rows [duplicate]

I have this table: ID Value ----------------- 3 A1 4 A2 8 A20 10 A10 I have to create ...
Loobe's user avatar
  • 3
-4 votes
1 answer
45 views

please explain the query

This looks like what I need as well. However, not being proficient in query making sense out of some of this.. so can you please clarify some things for me? ;WITH x AS <--- is this a comment? ( ...
Detox's user avatar
  • 1
-4 votes
1 answer
2k views

Horizontal to vertical table

I have this query SELECT quiz_id, COUNT(case when options LIKE '%question_id_8":"1%' then 1 else null end) as 'answered 1', COUNT(case when options LIKE '%question_id_8":"2%' then ...
Sarah Blo's user avatar
-5 votes
2 answers
128 views

Get count from SQL Server

I have the table like this: ID Office_Date Login_Time 397 2015-09-21 00:00:00 2015-09-21 09:00:00.000 397 2015-09-22 00:00:00 2015-09-22 10:00:04.000 397 2015-09-23 00:00:00 2015-09-23 08:...
Ganesh_55's user avatar

1
6 7 8 9
10