使用sum将行分组为列

时间:2016-04-09 10:21:55

标签: mysql group-by sum

假设我们有这张表:

CREATE TABLE `table1` (
`Name` CHAR(50) NOT NULL,
`Type` CHAR(50) NOT NULL,
`Value` DOUBLE NOT NULL
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB;


 ---------------------------------
|   Name   |   Type   |   Value   | 
 ---------------------------------   
|   Dep1   |   Cash   |   100     | 
 ---------------------------------  
|   Dep1   |   Card   |   200     | 
 ---------------------------------  
|   Dep2   |   Cash   |   300     | 
 ---------------------------------  
|   Dep2   |   Card   |   400     | 
 ---------------------------------

如何创建MySQL select查询来转换像这样的列中的行? 我必须提到“名称”列有动态值!

 --------------------------------
|   Name   |   Cash   |   Card   |    
 --------------------------------   
|   Dep1   |    100   |    200   |     
 --------------------------------   
|   Dep2   |    300   |    400   |
 --------------------------------  

0 个答案:

没有答案