SQL行列转换算法1
Jun 07, 2016 pm 02:54 PM请用一个sql语句得出结果 从table1,table2中取出如table3所列格式数据,注意提供的数据及结果不准确,只是作为一个格式向大家请教。 如使用存储过程也可以。 table1 月份mon 部门dep 业绩yj ------------------------------- 一月份 01 10 一月份 02 10 一月
请用一个sql语句得出结果从table1,table2中取出如table3所列格式数据,注意提供的数据及结果不准确,只是作为一个格式向大家请教。
如使用存储过程也可以。
table1
月份mon 部门dep 业绩yj
-------------------------------
一月份 01 10
一月份 02 10
一月份 03 5
二月份 02 8
二月份 04 9
三月份 03 8
table2
部门dep 部门名称dname
--------------------------------
01 国内业务一部
02 国内业务二部
03 国内业务三部
04 国际业务部
table3 (result)
部门dep 一月份 二月份 三月份
--------------------------------------
01 10 null null
02 10 8 null
03 5 null 8
04 null 9 null
------------------------------------------
select dname,b.yj '一月份',c.yj '二月份',d.yj '三月份' from table2 a left join table1 b on a.dep=b.dep and b.mon='一月份' left join table1 c on a.dep = c.dep and c.mon='二月份' left join table1 d on a.dep = d.dep and d.mon='三月份'

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What is the difference between HQL and SQL in Hibernate framework?

CLIP-BEVFormer: Explicitly supervise the BEVFormer structure to improve long-tail detection performance

Practical tips for converting full-width English letters into half-width form

Implementing Machine Learning Algorithms in C++: Common Challenges and Solutions

How to convert qq music to mp3 format Convert qq music to mp3 format on mobile phone

Detailed explanation of the implementation method of converting PHP months to English months

Explore the underlying principles and algorithm selection of the C++sort function

PHP Tutorial: How to convert int type to string
