I. Original data: select inman,indate from [ fp_db ] . [ dbo ] . [ ppezhpbb where indate > " 2016-5-1 " and indate 2016-6-1 " ORDER by indate Two. After conversion:SELECT CONVERT(varchar( -), Indate, at) Indate,sum( Case
---row to column--pivotCREATE TABLE TempTable(ID int primary key identity (.),Student nvarchar (36),[Subject] nvarchar (36),Score int,)SELECT * FROM TempTableINSERT into temptable values (' Zhang San ', ' language ', ' 90 ')INSERT into temptable
This is a more classic row-to-column. With fewer SQL statements, you can implement row-to-column. But this row-to-column needs to be developed two times according to your business needs, customized and or rewritten according to your needs.Let's talk
1 CREATE TABLESC2 3 (4 5StudentNVARCHAR( -),6 7CourseNVARCHAR( -)8 9 )Ten One INSERT intoSC A - SELECTN'Zhang San'N'College Chinese' UNION All - the SELECTN'John Doe'N'College Chinese' UNION All - - SELECTN'Zhang San'N'Calligraphy
-----------The original table-------------------Student classes score Zhang San Chinese AboutZhang San Mathematics theZhang San Physics theJohn Doe Language AboutJohn Doe Mathematics -John Doe Physics94------------------------------------1.
SQL Server 2005 provides a new way to row and column conversions, and here is an example for reference:if object_id('TB') is not NULL Drop TabletbtestGoCreate TableTbtest (Productvarchar(Ten), Quarterlyvarchar(Ten), Salesint)Insert
First we set up a table, named Rtoc, each field of the design such as, respectively, is Name,course,score, representing the name, scores and scores,.
2We added data to the table to add Xiao Ming and floret of the language and math scores.
3Next,
Original address: http://blog.csdn.net/kiki113/article/details/4105929 column conversion and other classic SQL statements1.--Row and column conversionsOriginal table: Name account ScoreZhang San Language 80Zhang San Mathematics 90Zhang San Physics 85
First, the use of the sceneWhen the system has summary and detailed requirements, generally through the implementation of SQL, summary is based on the conditions to display all the data, detail is a summary of the corresponding detailed
Build table:CREATE TABLE Studentinfo (Name varchar (20),Subject varchar (20),Score number (3,1));Insert Record:INSERT into studentinfo values (' Zhang San ', ' language ', 69);INSERT into studentinfo values (' Zhang San ', ' math ', 70);INSERT into
1 use [aps_future_ft] 2 GO 3/****** object:storedprocedure [dbo]. [A_crudeprice] Script DATE:2013/11/5 19:13:21 ******/4 SET ANSI_NULLS on 5 go 6 SET QUOTED_IDENTIFIER on 7 Go 8--==================== ========================= 9--Author:
I. Original data: select inman,indate from [ fp_db ] . [ dbo ] . [ ppezhpbb where indate > " 2016-5-1 " and indate 2016-6-1 " ORDER by indate Two. Post-conversion (dynamic splicing of SQL):--data Pre-existing temp
A: PrefaceIn some of the projects we do, we often encounter the problem of converting rows into columns, and here's a summary: convert one format to figure two. Figure 22: First insert data into the database.IF object_id('Tmark') is not NULL DROP
Use an SQL statement to obtain the results and extract the data in the format listed in table3 from table1 and table2. Note that the provided data and results are not accurate, but you can ask for advice as a format. You can also use the stored
(1) display and sort row numbers1. SQL Server row number A. SQL 2000 uses identity (int,) and temporary tables to display row numbers.SELECTIdentity (int, 1, 1) as rownum,[DataID]INTO #1FROM DATASOrder by DataID;SELECT * FROM #1B. SQL 2005 provides
/*
Title: normal row/column conversion (Version 2.0)
Note: normal row/column conversion (version 1.0) only provides static and dynamic writing for SQL Server 2000, and Version 2.0 adds SQL Server 2005 related writing.
Question: Suppose there is
Create table t (company varchar (30), goods varchar (30), value int)
Insert into t
Select 'compal', 'compute', 500 union all
Select 'compual', 'cpu ', 400 union all
Select 'compal', 'mouse ', 200 union all
Select 'fox', 'compute', 450 union
Original address: http://blog.csdn.net/kiki113/article/details/4105929 row and column conversion and other classic SQL statements
1. -- column and column Conversion
Original table: name, subject scoreZhang San Chinese 80Zhang San, mathematics
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.