饿虎岗资源网 Design By www.oxmxm.com
现有两表A,B

A表存储商品点击日志,B表存储商品

要求显示当天所有商品点击量列表并附带总数并按天排序
复制代码 代码如下:
declare @sql varchar(2000)
set @sql='select CONVERT(varchar(100), a.[Time], 23) as 时间,count(b.title) as 总数'
select @sql =@sql+ ',sum(case b.title when '''+Title+''' then 1 else 0 end) as '+'['+Title+']'
from (select distinct title from B) as B
set @sql=@sql+' from A as a left join B as b on a.AId=B.Aid
group by CONVERT(varchar(100), a.[Time], 23) order by CONVERT(varchar(100), a.[Time], 23) desc'
exec(@sql)

显示结果
时间 总数 商品1 商品2 商品3 2013-11-11 5 1 0 4 2013-11-10 13 2 11 1
饿虎岗资源网 Design By www.oxmxm.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
饿虎岗资源网 Design By www.oxmxm.com