mysql 数据统计 mysql 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://blog.csdn.net/acmain_chm/article/details/4283943MySQL交叉表在某些数据库中有交叉表,但在MySQL中却没有这个功能,但网上看到有不少朋友想找出一个解决方法,特发贴集思广义。http://topic.csdn.net/u/20090530/23/0b782674-4b0b-4cf5-bc1a-e8914aaee5ab.html?96198现整理解法如下:数据样本: create table tx( id int primary key, c1 c... 多谢版主帮忙,看了这篇博文,可以解决我的问题的70%,但是现在还有如下问题需请教:SELECT classify as '-',#请注意?号IF((FROM_UNIXTIME(startDate,'%m')='01' || FROM_UNIXTIME(startDate,'%m')='12') && startDate >= UNIX_TIMESTAMP(CONCAT(2013,'-12-15')) && startDate <= UNIX_TIMESTAMP(CONCAT(2014,'-01-15')),?,0 ) AS '1月使用次数',sum(IF((FROM_UNIXTIME(startDate,'%m')='01' || FROM_UNIXTIME(startDate,'%m')='12') && startDate >= UNIX_TIMESTAMP(CONCAT(2013,'-12-15')) && startDate <= UNIX_TIMESTAMP(CONCAT(2014,'-01-15')),duration,0)) AS '1月合计',IF((FROM_UNIXTIME(startDate,'%m')='01' || FROM_UNIXTIME(startDate,'%m')='02') && startDate >= UNIX_TIMESTAMP(CONCAT(2014,'-01-16')) && startDate <= UNIX_TIMESTAMP(CONCAT(2014,'-02-15')),?,0) AS '2月使用次数',sum(IF((FROM_UNIXTIME(startDate,'%m')='01' || FROM_UNIXTIME(startDate,'%m')='02') && startDate >= UNIX_TIMESTAMP(CONCAT(2014,'-01-16')) && startDate <= UNIX_TIMESTAMP(CONCAT(2014,'-02-15')),duration,0)) AS '2月合计',IF((FROM_UNIXTIME(startDate,'%m')='02' || FROM_UNIXTIME(startDate,'%m')='03') && startDate >= UNIX_TIMESTAMP(CONCAT(2014,'-02-16')) && startDate <= UNIX_TIMESTAMP(CONCAT(2014,'-03-15')),?,0) AS '3月使用次数',sum(IF((FROM_UNIXTIME(startDate,'%m')='02' || FROM_UNIXTIME(startDate,'%m')='03') && startDate >= UNIX_TIMESTAMP(CONCAT(2014,'-02-16')) && startDate <= UNIX_TIMESTAMP(CONCAT(2014,'-03-15')),duration,0)) AS '3月合计',IF((FROM_UNIXTIME(startDate,'%m')='03' || FROM_UNIXTIME(startDate,'%m')='04') && startDate >= UNIX_TIMESTAMP(CONCAT(2014,'-03-16')) && startDate <= UNIX_TIMESTAMP(CONCAT(2014,'-04-15')),?,0) AS '4月使用次数',sum(IF((FROM_UNIXTIME(startDate,'%m')='03' || FROM_UNIXTIME(startDate,'%m')='04') && startDate >= UNIX_TIMESTAMP(CONCAT(2014,'-03-16')) && startDate <= UNIX_TIMESTAMP(CONCAT(2014,'-04-15')),duration,0)) AS '4月合计',...sum(duration) as '合计'from t GROUP BY classify我想得出这种结果//使用次数:其实就是添加一条记录就等于使用一次,?号处该怎么写?1月使用次数,1月合计,2月使用次数,2月合计,3月使用次数,3月合计... 1 5 0 0 2 10 一个数据读取的问题 存储过程中运用游标 perl(Class::MethodMaker) is needed by 怎么处理 请问varchar和text两种类型有什么区别? 在线求教mysql问题 如何将Execl中的Sheet的结构导入MySQL中 MM.MySQL 2.0.14 和 MySQL Connector/J 区别 想用phpmyadmin访问mysql,需要在mysql服务器上做些什么? 怪异的InnoDB类型错误, 求解? WAMP phpmyadmin 密码纠结从哪里开始设置? cetos安装mysql MySQL怎么样在同一实例不同数据库中进行表同步呢?
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...
SELECT classify as '-',
#请注意?号
IF((FROM_UNIXTIME(startDate,'%m')='01' || FROM_UNIXTIME(startDate,'%m')='12') && startDate >= UNIX_TIMESTAMP(CONCAT(2013,'-12-15')) && startDate <= UNIX_TIMESTAMP(CONCAT(2014,'-01-15')),?,0 ) AS '1月使用次数',
sum(IF((FROM_UNIXTIME(startDate,'%m')='01' || FROM_UNIXTIME(startDate,'%m')='12') && startDate >= UNIX_TIMESTAMP(CONCAT(2013,'-12-15')) && startDate <= UNIX_TIMESTAMP(CONCAT(2014,'-01-15')),duration,0)) AS '1月合计',IF((FROM_UNIXTIME(startDate,'%m')='01' || FROM_UNIXTIME(startDate,'%m')='02') && startDate >= UNIX_TIMESTAMP(CONCAT(2014,'-01-16')) && startDate <= UNIX_TIMESTAMP(CONCAT(2014,'-02-15')),?,0) AS '2月使用次数',
sum(IF((FROM_UNIXTIME(startDate,'%m')='01' || FROM_UNIXTIME(startDate,'%m')='02') && startDate >= UNIX_TIMESTAMP(CONCAT(2014,'-01-16')) && startDate <= UNIX_TIMESTAMP(CONCAT(2014,'-02-15')),duration,0)) AS '2月合计',IF((FROM_UNIXTIME(startDate,'%m')='02' || FROM_UNIXTIME(startDate,'%m')='03') && startDate >= UNIX_TIMESTAMP(CONCAT(2014,'-02-16')) && startDate <= UNIX_TIMESTAMP(CONCAT(2014,'-03-15')),?,0) AS '3月使用次数',
sum(IF((FROM_UNIXTIME(startDate,'%m')='02' || FROM_UNIXTIME(startDate,'%m')='03') && startDate >= UNIX_TIMESTAMP(CONCAT(2014,'-02-16')) && startDate <= UNIX_TIMESTAMP(CONCAT(2014,'-03-15')),duration,0)) AS '3月合计',IF((FROM_UNIXTIME(startDate,'%m')='03' || FROM_UNIXTIME(startDate,'%m')='04') && startDate >= UNIX_TIMESTAMP(CONCAT(2014,'-03-16')) && startDate <= UNIX_TIMESTAMP(CONCAT(2014,'-04-15')),?,0) AS '4月使用次数',
sum(IF((FROM_UNIXTIME(startDate,'%m')='03' || FROM_UNIXTIME(startDate,'%m')='04') && startDate >= UNIX_TIMESTAMP(CONCAT(2014,'-03-16')) && startDate <= UNIX_TIMESTAMP(CONCAT(2014,'-04-15')),duration,0)) AS '4月合计',
...
sum(duration) as '合计'
from t GROUP BY classify
我想得出这种结果//使用次数:其实就是添加一条记录就等于使用一次,?号处该怎么写?
1月使用次数,1月合计,2月使用次数,2月合计,3月使用次数,3月合计...
1 5 0 0 2 10