各位 大侠hao菜鸟问一个问题表1如何通过查询得到如同表2的查询结果表1
Year Month Rate
2001 1 0.1
2001 2 0.2
2001 3 0.3
2001 4 0.4
2002 1 0.11
2002 2 0.22
2002 3 0.33
2002 4 0.44 表2
Year M1 M2 M3 M4
2001 0.1 0.2 0.3 0.4
2002 0.11 0.22 0.33 0.44
Year Month Rate
2001 1 0.1
2001 2 0.2
2001 3 0.3
2001 4 0.4
2002 1 0.11
2002 2 0.22
2002 3 0.33
2002 4 0.44 表2
Year M1 M2 M3 M4
2001 0.1 0.2 0.3 0.4
2002 0.11 0.22 0.33 0.44
解决方案 »
- mysql错误代码如何查看
- 从Access向mysql导入数据
- 求教求教求教mysql建表排错
- mysqldump 如何把 库的dll语句给导出
- JSP访问mysql数据库取一条数据时,速度很慢。。求优化方案!
- 〓〓【用group by 语句后,触发器写了出现的问题不解,100分请求帮助】〓〓
- mysql5,同一个连接中,怎样取得上一次自增字段产生的值?
- MySQL的存储过程如何退出
- windows下mysql怎样修改端口
- c3p0连接池配置文件中maxIdleTime小于数据库的timeout时间,为什么还会出现了使用了数据库已经超时的连接
- 新手 求助mysql 存储过程问题
- Mysql MyISAM数据库引擎发音
sum(case when month=1 then rate end) as M1,
sum(case when month=2 then rate end) as M2,
sum(case when month=3 then rate end) as M3,
sum(case when month=4 then rate end) as M4
from tb1
group by year
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...
sum(if(month=1,rate,0)) as M1,
sum(if(month=2,rate,0))as M2,
sum(if(month=3,rate,0)) as M3,
sum(if(month=4,rate,0)) as M4
from tb1
group by year