Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在mysql中将行转换为列_Mysql_Sql - Fatal编程技术网

如何在mysql中将行转换为列

如何在mysql中将行转换为列,mysql,sql,Mysql,Sql,如何在mysql中转换此表 month | Number_oF_User 1 | 3 2 | 13 3 | 2 12 | 3 皈依 month 1 2 3 12 number_of_user 3 13 2 3 您必须使用类似以下内容的查询: 挑选* 从…起 选择“用户数量”作为Itm、[1]、[2]、[3]、[4]、[5

如何在mysql中转换此表

month | Number_oF_User 
 1    |       3 
 2    |       13 
 3    |       2 
 12   |       3 
皈依

month             1    2     3        12
number_of_user    3    13    2         3

您必须使用类似以下内容的查询:

挑选* 从…起 选择“用户数量”作为Itm、[1]、[2]、[3]、[4]、[5]、[6]、[7]、[8]、[9]、[10]、[11]、[12] 从…起 选择MonthYour列作为Mon,即用户列的编号 从您的表名T1 -你的条件在哪里

) as SourceTable
Pivot
(
    Your Number_of_User Column
    For Mon in ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])
) as Your TableName t1
A -如果您希望水平地计算每行的总和,则将应用此选项
交叉应用从PaymentReceipt i中选择SUMCamount作为SumVal,AVGCamount作为AvgVal,其中i.PaymentType=a.Itm b

请参见使用case语句和动态查询对现有数据进行透视您是使用任何过程还是需要单语句查询