mysql 经典题目
2014-03-07 13:18
211 查看
题目1:实现如下效果
CREATE TABLE IF NOT EXISTS tb_amount( `Id` INT NOT NULL AUTO_INCREMENT, `Year` CHAR(4), `Month` CHAR(2), `Amount` DECIMAL(5,2), PRIMARY KEY(`Id`) ); INSERT INTO `tb_amount`(`Year`, `Month`, `Amount`) VALUES('1991', '1', '1.1'); INSERT INTO `tb_amount`(`Year`, `Month`, `Amount`) VALUES('1991', '2', '1.2'); INSERT INTO `tb_amount`(`Year`, `Month`, `Amount`) VALUES('1991', '3', '1.3'); INSERT INTO `tb_amount`(`Year`, `Month`, `Amount`) VALUES('1991', '4', '1.4'); INSERT INTO `tb_amount`(`Year`, `Month`, `Amount`) VALUES('1992', '1', '2.1'); INSERT INTO `tb_amount`(`Year`, `Month`, `Amount`) VALUES('1992', '2', '2.2'); INSERT INTO `tb_amount`(`Year`, `Month`, `Amount`) VALUES('1992', '3', '2.3'); INSERT INTO `tb_amount`(`Year`, `Month`, `Amount`) VALUES('1992', '4', '2.4'); SELECT `Year`, (SELECT Amount FROM tb_amount m WHERE `Month`=1 AND m.`Year`=tb_amount.`Year`) AS m1, (SELECT Amount FROM tb_amount m WHERE `Month`=2 AND m.`Year`=tb_amount.`Year`) AS m2, (SELECT Amount FROM tb_amount m WHERE `Month`=3 AND m.`Year`=tb_amount.`Year`) AS m3, (SELECT Amount FROM tb_amount m WHERE `Month`=4 AND m.`Year`=tb_amount.`Year`) AS m4 FROM tb_amount GROUP BY `Year`;
相关文章推荐
- 【mysql经典题目】行转列
- MYSQL经典题目
- mysql原理经典题目
- 几道经典的Mysql题目
- 【mysql经典题目】科目成绩都大于80分\每个科目的第一名\总成绩排名
- 十个利用矩阵乘法解决的经典题目
- 经典sql语句大全-非常有用(特指Mysql)
- MySql经典实用语句
- MySQL-经典练习题
- leetcode -- Reverse Nodes in k-Group -- 经典题目,要重写
- 33条C#、.Net经典面试题目及答案
- 经典MySQL语句收藏(高手必备)
- 题目6:MySQL----------Employees Earning More Than Their Managers
- 2015年9-10月互联网秋招经典面试题目汇总
- poj 2763 Housewife Wind(LCA经典题目 处理树链)
- MySQL经典书籍推荐
- java经典题目!
- 计算机等级考试二级C语言超级经典400道题目(6)
- 【大型网站技术实践】初级篇:搭建MySQL主从复制经典架构
- 算法设计几个经典思维题目