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 mysql 日期类型问题 mysql有没有类似with NOLOCK的表达 改写一个触发器 应该很简单 mysql 工具问题 PL/SQL中难道不支持for和if的嵌套?? 求SQL代码如何实现 [急求]关于in排序 的问题! 在linux下面有没有Mysql的图形界面管理软件使用呢? 求教:access数据库转SQL SERVER数据库 mysql源碼方面的資料。 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