日期:2014-05-16 浏览次数:20751 次
mysql> select * from config; +----+----------+ | id | name | +----+----------+ | 1 | salary | | 2 | bonus | | 3 | overtime | +----+----------+ 3 rows in set (0.00 sec) mysql> select * from data; +--------+-------+----------+ | salary | bonus | overtime | +--------+-------+----------+ | 1 | 2 | 4 | | 3 | 3 | 3 | +--------+-------+----------+ 2 rows in set (0.00 sec) mysql> select @sql := concat("select ", group_concat(name), " from data;") -> from config -> where id in (1, 2); +--------------------------+ | @sql := concat("select ", group_concat(name), " from data;") | +--------------------------+ | select salary,bonus from data; | +--------------------------+ 1 row in set (0.00 sec) mysql> mysql> prepare sp from @sql; Query OK, 0 rows affected (0.00 sec) Statement prepared mysql> execute sp; +--------+-------+ | salary | bonus | +--------+-------+ | 1 | 2 | | 3 | 3 | +--------+-------+ 2 rows in set (0.00 sec) mysql> drop prepare sp; Query OK, 0 rows affected (0.00 sec)
------解决方案--------------------
http://blog.csdn.net/acmain_chm/article/details/4283943
MySQL交叉表
在某些数据库中有交叉表,但在MySQL中却没有这个功能,但网上看到有不少朋友想找出一个解决方法,特发贴集思广义。http://topic.csdn.net/u/20090530/23/0b782674-4b0b-4cf5-bc1a-e8914aaee5ab.html?96198现整理解法如下:数据样本: create table tx( id int primary key, c1 c...