易截截图软件、单文件、免安装、纯绿色、仅160KB

Mysql 交叉查询

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;


相关文档:

A simple mysql sample

#include <winsock2.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <mysql.h>
#pragma comment(lib,"libmysql")
int _tmain(int argc, _TCHAR* argv[])
{
MYSQL* mysql;
MYSQL_RES* results;
MYSQL_ROW record;
mysql = mysql_init(NULL);
if(! ......

MySQL 4.1(或以上) 中文乱码原因及解决方法

很多朋友都有过这样的经历,将mysql升级到4.1(或以上)版本后,旧的程序从数据库读出来的都变成乱码了.这个问题网上很多这方面的讨论,其实手册上已经有关于这方面的详细说明,
以下内容摘自mysql手册,
产生这个问题的原因是:
MySQL 4.1.x开始支持以下这些事情
·         使 ......

创建mysql实例

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 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号