SQL row/column conversion algorithm 1

Source: Internet
Author: User
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 procedure. Table July mon Department dep performance yj ----------------------------------- July 0110 July 0210 July

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 procedure. Table July mon Department dep performance yj ----------------------------------- February 01 10 February 02 10 February

Use an SQL statement to obtain the result.
Retrieve 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 procedure.

Table1

Month mon Department dep performance yj
-------------------------------
February 01 10
February 02 10
March January
March 02 8
March February
March

Table 2

Department dep Department name dname
--------------------------------
01 domestic business 1
02 domestic business department 2
03 domestic business department 3
04 International Business Department

Table3 (result)

Department dep, January, January
--------------------------------------
01 10 null
02 10 8 null
03 5 null 8
04 null 9 null

------------------------------------------

<无>
Select dname, B. yj'february ', c. yj'february ', d. yj'february 'from table2 a left join table1 B on. dep = B. dep and B. mon = 'february 'left join table1 c on. dep = c. dep and c. mon = 'february 'left join table1 d on. dep = d. dep and d. mon = 'february'

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.