首页 新闻 会员 周边

数据的显示情况

0
悬赏园豆:10 [已解决问题] 解决于 2012-03-30 23:08

数据库显示的页面                                           页面显示的数据

      

说明:页面中显示的表头是数据库中表的reson列里面的所有数据,是固定的,amount是数量。页面中显示的数据是按天数来查的,如果该天查到的reason原因中,有些reason原因不存在的话就用0表示。

请教各位大侠们:我要做成这种形式的,在数据层和服务端中我应该怎么操作,具体应该怎么去写。

程旭媛的主页 程旭媛 | 初学一级 | 园豆:79
提问于:2012-03-29 23:24
< >
分享
最佳答案
0

你的第一个图是 是数据库的原始数据   还是你写查询语句进行的处理过的数据  如聚合函数?

如果数据库表的数据是这样的话 下面的sql语句

select showtime,isnull(sum(unknow),0) as unknow ,isnull(sum(noidea),0) as noidea ,
isnull(sum(soso),0) as soso,isnull(sum(understand),0) as understand
from
(select showtime,case when reason='不明白' then Amount end unknow,
case when reason='不清楚' then Amount end noidea,
case when reason='还好' then Amount end soso,
case when reason='了解' then Amount end understand
from test1 group by showtime,reason,Amount) as temp
group by showtime

--表test1 你可以替换为 你的查询语句

查询结果 

showtime                unknow      noidea      soso        understand
----------------------- ----------- ----------- ----------- -----------
2012-01-12 00:00:00.000 0 0 5 4
2012-02-10 00:00:00.000 3 0 0 0
2012-11-18 00:00:00.000 2 3 0 3
2012-12-21 00:00:00.000 0 1 0 0



你应该把的表结构 给说出来 而不是你查出来的数据 我还纠结哪有这样建表的啊  

收获园豆:10
Fishboy | 菜鸟二级 |园豆:244 | 2012-03-30 11:18

嗯!对,是处理后的数据。

程旭媛 | 园豆:79 (初学一级) | 2012-03-30 11:20

@求解=: 效率问题先不考虑  你要把你的标的结构给说清楚  我只是按照图片上表关系来的

Fishboy | 园豆:244 (菜鸟二级) | 2012-03-30 12:04

@Fishboy: amount列是我统计出来的数据,表的本身没有该列。

程旭媛 | 园豆:79 (初学一级) | 2012-03-30 13:39
select showtime,isnull(sum(unknow),0) as unknow ,isnull(sum(noidea),0) as noidea ,
isnull(sum(soso),0) as soso,isnull(sum(understand),0) as understand
from
(
select showtime,case when reason='不明白' then count(reason) end unknow,
case when reason='不清楚' then count(reason) end noidea,
case when reason='还好' then count(reason) end soso,
case when reason='了解' then count(reason) end understand
from test1 group by showtime,reason
) as temp
group by showtime
--这样行不行


@求解=: 

Fishboy | 园豆:244 (菜鸟二级) | 2012-03-30 13:53

@Fishboy: 不行

程旭媛 | 园豆:79 (初学一级) | 2012-03-30 16:36

@求解=: 你数据表结构都不给  只给我个结果集  我也束手无策 

Fishboy | 园豆:244 (菜鸟二级) | 2012-03-30 16:40

@Fishboy: 谢谢啦!我用另外一种方式解决啦。

程旭媛 | 园豆:79 (初学一级) | 2012-03-30 23:07
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册