【转】mysql行列转换方法总结】的更多相关文章

[转载]mysql行列转换方法总结 [MySQL] 行列转换变化各种方法实现总结(行变列报表统计.列变行数据记录统计等) Mysql 列转行统计查询 .行转列统计查询 在某些数据库中有交叉表,但在MySQL中却没有这个功能,但网上看到有不少朋友想找出一个解决方法,特发贴集思广义.http://topic.csdn.net/u/20090530/23/0b782674-4b0b-4cf5-bc1a-e8914aaee5ab.html?96198…
转:http://blog.chinaunix.net/uid-7692530-id-2567582.html 在某些数据库中有交叉表,但在MySQL中却没有这个功能,但网上看到有不少朋友想找出一个解决方法,特发贴集思广义.http://topic.csdn.net/u/20090530/23/0b782674-4b0b-4cf5-bc1a-e8914aaee5ab.html?96198现整理解法如下: 数据样本: create table tx(  id int primary key,  c…
这是一道行转列并且构造交叉表的问题: http://topic.csdn.net/u/20090530/23/0b782674-4b0b-4cf5-bc1a-e8914aaee5ab.html 数据样本: create table tx( id int primary key, c1 char(2), c2 char(2), c3 int); insert into tx values(1 ,'A1','B1',9),(2 ,'A2','B1',7),(3 ,'A3','B1',4),(4 ,'…
mysql 行列动态转换(列联表,交叉表) (1)动态,适用于列不确定情况 create table table_name( id int primary key, col1 char(2), col2 char(2), col3 int); insert into table_name values(1 ,'A1','B1',9),(2 ,'A2','B1',7),(3 ,'A3','B1',4),(4 ,'A4','B1',2),(5 ,'A1','B2',2),(6 ,'A2','B2',…
分类: Mysql/postgreSQL 在某些数据库中有交叉表,但在MySQL中却没有这个功能,但网上看到有不少朋友想找出一个解决方法,特发贴集思广义.http://topic.csdn.net/u/20090530/23/0b782674-4b0b-4cf5-bc1a-e8914aaee5ab.html?96198现整理解法如下: 数据样本: create table tx( id int primary key, c1 ), c2 ), c3 int ); insert into tx v…
create table score( name ), math int, english int ); ,); ,); ,); ,); SHOW tables; SELECT * from score; --行列转换: select c2 as '课程', )) '甲', )) '乙', )) '丙', )) '丁' from( select name c1,'math' c2,math c3 from score GROUP BY name union select name,'englis…
mysql> select TBL_ID,CREATE_TIME,LAST_ACCESS_TIME,TBL_NAME,TBL_TYPE from TBLS; +--------+-------------+------------------+----------------------+---------------+ | TBL_ID | CREATE_TIME | LAST_ACCESS_TIME | TBL_NAME | TBL_TYPE | +--------+------------…
列转行: mysql> select * from test; +------+----------+-------+ | id | subject | score | +------+----------+-------+ | | | | | | +------+----------+-------+ rows in set (0.00 sec) mysql end) politics from test group by id; +--------+---------+------+----…
行列相互转换 /*创建表*/ CREATE TABLE ic ( NAME ), Product ), amount INT ); INSERT INTO ic VALUES (), (), (), (), (), (), (), (), (); SELECT * FROM ic; 想要用product列的值做列,列名变为 name,A1,A2,A3. CREATE TABLE ic_1 SELECT name , )) AS A1, )) AS A2, )) AS A3 FROM ic GRO…
一.第一种 原数据表 转换后 DROP TABLE IF EXISTS tempdynamic; CREATE TEMPORARY TABLE tempdynamic ( SELECT p.fsPaymentName,sr.fsPaymentId,sh.fsShiftName,SUM(sr.fdReceMoney) as AmtTotal FROM tbsell as s INNER JOIN tbSellReceive as sr ON s.fsSellNo=sr.fsSellNo AND s…