table A 三个字段为
id type value
1 1 50
1 1 100
1 2 100
1 2 50
2 1 50
2 1 30
2 2 50
2 2 50table B
id type1_value type2_value
1 150 150
2 80 100问题是:已知A表,怎么生成B表,用sql语句实现?
id type value
1 1 50
1 1 100
1 2 100
1 2 50
2 1 50
2 1 30
2 2 50
2 2 50table B
id type1_value type2_value
1 150 150
2 80 100问题是:已知A表,怎么生成B表,用sql语句实现?
解决方案 »
- 在window 平台安装mysql ,一般设置什么默认字符集好
- 如何关闭当前session记录二进制日志的功能
- mysql内存数据库大小问题
- 也谈关于绿色版my.ini相对路径设置的问题
- 请大家帮忙看看:我的update语句为什么不能更新ok数据表?
- WWWWA ,,时间函数问T续,,,,,
- 如何在java中导出mysql数据库
- 这句sql为什么在Mysal中不能执行
- 请教怎样把SQL2000数据库导出成.csv文件????请问详细步骤,而且不要丢数据~~~
- 将系统时间改为2099年,mysql连接失败是什么原因?
- 为什么数据库表要建立索引呢?我们的java程序里在写sql语句的时候怎么没有用到索引啊?
- 异地读取数据库中文显示乱码
select id,
sum(if(type=1,value,0)) as type1_value,
sum(if(type=2,value,0)) as type2_value
from A
group by id
select id,
sum(if(type=1,value,0)) as type1_value,
sum(if(type=2,value,0)) as type2_value
from A
group by id
table B
id type1_value type2_value sum period_id
1 150 150 300 1
2 80 100 180 1