Reference article:Http://www.williamsang.com/archives/1508.htmlScenario BriefThe school records the results, each person's choice course is different, and later will add the course, so do not need to take all the courses as a column. Database grade
SQL row-to-column and column-to-row code details, SQL-to-row
Switching between rows and columns is a common requirement. Implementation methods include the case when method and the built-in unlock and ununlock methods after 2005.After reading the
Original: SQL row to column summary Pivot Unpivot usage pivot is used to rotate column values to column names (row to column), and the general syntax for pivot is implemented in SQL Server 2000 with an aggregate function with a case statement: Pivot
650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M01/91/85/wKioL1j2vuCiSTLcAAAsXjQIOLM136.jpg-wh_500x0-wm_ 3-wmp_4-s_1989208398.jpg "title=" qq picture 20170419093438.jpg "alt=" Wkiol1j2vucistlcaaasxjqiolm136.jpg-wh_50 "/>Title: There is an
1, Row to columnAvailable data:Expected data:1.1 Build Table DataIF object_id (' temp_20170701 ', ' u ') is not NULL DROP TABLE temp_20170701 CREATE table temp_20170701 (ID INT PRIMARY KEY IDE Ntity (+), NAME 1.2.1 Static implementationSELECT Name,
CREATE PROCEDURE Proc_goodsskucombineAsIF EXISTS (SELECT * from sys.objects WHERE object_id = object_id (N ' [dbo].[ GOODSTEMP1] ') and type in (N ' U '))DROP TABLE [dbo]. GoodsTemp1 ; with Roy as(select Number,colorname,sizename,row=row_number ()
1. Create a table and prepare the next data source1 Create TableStudent2 (3Idint Primary Key Identity(1,1) not NULL,4Stunamenvarchar( -),5Coursenamenvarchar( -),6Scoreint,7CreatetimeDateTime 8 9 )Ten One Insert intoStudentValues('Zhang
Original: SQL row to Column PIVOT column career UNPIVOTOne:Existing table one (T_TABLE1), want to convert to table two (t_table2) format.Table I:
year
company
revenue
2013
SQL row-to-column and column-changing careersThe ranks of each other, is a frequently encountered demand. The implementation method is implemented with case-when mode and a built-in pivot and Unpivot method after 2005.After reading the technical
1. Using case and then1 SelectDeptid,d.depname,sum( Case [Type] when 0 ThenCountvisitEnd) as 'Newstype',sum( Case [Type] when 1 ThenCountvisitEnd) as 'Questiontype',sum( Case [Type] when 2 ThenCountvisitEnd) as 'Policytype',sum( Case [Type]
TurnClassic SQL issues: Row to column posted 5 month ago (2015-09-19 17:49) Read (2855) | Reviews0) I want to collect this article .likes0The school records the results, each person's choice course is different, and later will add the course, so do
Build table:CREATE TABLE Studentinfo (Name varchar, subject varchar (+), score number (3,1)); Insert Record:INSERT into studentinfo values (' Zhang San ', ' language ', 69);INSERT into studentinfo values (' Zhang San ', ' math ', 70);INSERT into
SQL Row to Column rollupPivot is used to rotate column values to column names (row to column), and SQL Server 2000 can be implemented with an aggregate function with a case statementThe general syntax for pivot is: Pivot (aggregate function (column)
Purpose: To merge multi-line values of the same condition into the same column.1. Create a Test table:CREATE TABLE [dbo].[tb_01]( [SN] [nvarchar]( -)NULL, [Step_name] [nvarchar]( -)NULL, [sdate] [datetime] NULL) on [PRIMARY]2. Insert the
SQL row to column, SQL to Column
Row-to-Column
Table Structure:
Subject
Yw Language
Sx mathematics
Table data:
SQL conversion:
1 select name, 2 max (case subject when 'yw' then score else ''end) as yw, 3 max (case subject when 'sx 'then
A simple SQL row-column Conversion
Author: eaglet
In database development, we often encounter the problem of column/column conversion, such as the following problems, three tables for departments, employees, and employees. We need to count a list
A simple SQL row and column conversion
Author:eaglet
In database development, we often encounter the problem of row and column conversion, such as the following question, department, employee and employee type three sheets, we want to count similar
If object_id (' TB ') is not null drop table TBGoCREATE table TB (name varchar (10), course varchar (10), fractional int)INSERT into TB values (' Zhang San ', ' language ', 74)INSERT into TB values (' Zhang San ', ' math ', 83)INSERT into TB values (
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.