CREATE TABLE `taa` (
`year` varchar(4) DEFAULT NULL,
`month` varchar(2) DEFAULT NULL,
`amount` double DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf
"year","month",amount
"1991","1",1.1
"1991","2",1.2
"1991","3",1.3
"1991","4",1.4
"1992","1",2.1
"1992","2",2.2
"1992","3",2.3
"1992","4",2.4
1.select a.year,a.m1,a.m2,b.m3,b.m4 from
(select year,
sum(if(month=1,amount,0)) as m1,
sum(if(MONTH=2,amount,0)) AS m2
from taa
group by year) a,
(SELECT year,
SUM(IF(MONTH=3,amount,0)) AS m3,
SUM(IF(MONTH=4,amount,0)) AS m4
from taa
GROUP BY YEAR) b
where a.year=b.year;
2.select year,
max((case month when 1 then amount end)) as m1,
max((CASE MONTH WHEN 2 THEN amount END)) AS m2,
max((CASE MONTH WHEN 3 THEN amount END)) AS m3,
max((CASE MONTH WHEN 4 THEN amount END)) AS m4
from taa
group by year;
很多朋友都有过这样的经历,将mysql升级到4.1(或以上)版本后,旧的程序从数据库读出来的都变成乱码了.这个问题网上很多这方面的讨论,其实手册上已经有关于这方面的详细说明,
以下内容摘自mysql手册,
产生这个问题的原因是:
MySQL 4.1.x开始支持以下这些事情
· 使 ......
1. 在/etc/my.cnf中加入一下内容
[mysqld_dev]
socket=/tmp/mysql.sock
port=3307
pid-file=/var/run/mysqld/mysqld_dev.pid
datadir=/var/lib/mysql_dev
log=/var/log/mysqld_dev.log
log-error=/var/log/mysqld_dev.err.log
user=mysql
2. 根据以上内容创建目录和文件
mkdir /var/lib/mysqld_dev
chown mys ......