CREATE TABLE `sys_online` (
`uid` int(11) NOT NULL,
`lastupdate` int(11) NOT NULL DEFAULT '0',
`onlinetime` int(11) NOT NULL DEFAULT '0',
`online` int(11) DEFAULT '0' COMMENT '鏈€杩戜竴娆′笂绾挎椂闂?,
`day` int(11) DEFAULT '0' COMMENT '浠婂ぉ',
`daytime` int(11) DEFAULT '0' COMMENT '褰撳ぉ绱Н鏃堕棿',
`logincount` int(11) DEFAULT NULL,
PRIMARY KEY (`uid`),
KEY `lastupdate` (`lastupdate`) USING BTREE
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='鍦ㄧ嚎鎯呭喌' 将表结构中的内容转换为不同时间段内的注册人数:即显示为: 1分钟内/1-3分钟/3-5分钟/5-10分钟/10-15分钟/15-30分钟/30-60分钟/1-2小时/2-3小时/3小时以上/日期 其中onlinetime为在线时长,如何写SQL,谢谢!
`uid` int(11) NOT NULL,
`lastupdate` int(11) NOT NULL DEFAULT '0',
`onlinetime` int(11) NOT NULL DEFAULT '0',
`online` int(11) DEFAULT '0' COMMENT '鏈€杩戜竴娆′笂绾挎椂闂?,
`day` int(11) DEFAULT '0' COMMENT '浠婂ぉ',
`daytime` int(11) DEFAULT '0' COMMENT '褰撳ぉ绱Н鏃堕棿',
`logincount` int(11) DEFAULT NULL,
PRIMARY KEY (`uid`),
KEY `lastupdate` (`lastupdate`) USING BTREE
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='鍦ㄧ嚎鎯呭喌' 将表结构中的内容转换为不同时间段内的注册人数:即显示为: 1分钟内/1-3分钟/3-5分钟/5-10分钟/10-15分钟/15-30分钟/30-60分钟/1-2小时/2-3小时/3小时以上/日期 其中onlinetime为在线时长,如何写SQL,谢谢!
-- 创建数据表
create table tba
(
日期 datetime,
金额 varchar(10),
类型 varchar(10)
)
go
--测试数据insert into tba select '2011-8-1','20','销售' union all
select '2011-8-1','5','退货' union all
select '2011-8-2','30','销售' union all
select '2011-8-2','10','销售' union all
select '2011-8-2','10','退货'
select * from tba;select convert(varchar(10),日期,120) as 日期,
sum(case 类型 when '销售' then 金额 else 0 end) 销售金额,
sum(case 类型 when '退货' then 金额 else 0 end) 退货金额
from tba
group by 日期2011-08-01 00:00:00.000 20 销售
2011-08-01 00:00:00.000 5 退货
2011-08-02 00:00:00.000 30 销售
2011-08-02 00:00:00.000 10 销售
2011-08-02 00:00:00.000 10 退货2011-08-01 20 5
2011-08-02 40 10