select p.devicecodeS ,z.nodename ,z.nidename ,z.direction ,z.roadtype ,p.status from
(select r.linkid as devicecodeS,count(r.status) as status from ROADSTATUSHISTORY r
where
'2012-07-11 00:00:00'<to_char(r.timetag,'yyyy-MM-dd hh24:mi:ss')
and
'2012-07-12 00:00:00'>to_char(r.timetag,'yyyy-MM-dd hh24:mi:ss')
and
r.status<=10
group by r.linkid) p,zlinks z
where z.linkid=p.devicecodeS order by p.devicecodeS asc
查询出的结果是
id linkid nodename nidename direction podatype status
1 11 南二环经七路十字 经七路西影路十字 由北向南 南二环经七路 2
2 48 雁塔路立交 长安路立交 由东向西 南二环中段 4
3 52 长安路立交 雁塔路立交 由西向东 南二环中段 4
4 82 朝阳门 环城北路东段 由南向北 环城东路北段 1
5 89 钟楼 北大街莲湖路交叉口 由南向北 北大街 1
6 131 环城北路东段 朝阳门 由北向南 环城东路北段 1
7 137 北大街莲湖路交叉口 钟楼 由北向南 北大街 1
这只是一天的数据,我想查询一周的数据显示的结果是这样的:
id linkid nodename nidename direction podatype status status1 status2 status3 status4 status5 status6
1 11 南二环经七路十字 经七路西影路十字 由北向南 南二环经七路 2 5 7 1 2 1 1
2 48 雁塔路立交 长安路立交 由东向西 南二环中段 4 6 1 3 5 2 1
.............................
在线等待,请给位高手,大虾,大哥,大姐帮帮忙
6 个解决方案
#1
分开判断吧
select ...
sum(decode(to_char(timetag,'yyyy-mm-dd'),'2012-07-11',1,0) c1,
sum(decode(to_char(timetag,'yyyy-mm-dd'),'2012-07-12',1,0) c2,
...
from tb1
group by ...
#2
能够详细点吗?
#3
时间字段是哪个,没有时间字段,我哪知道哪个状态该放在周几?
#4
r.timetag
#5
select p.devicecodeS ,
z.nodename ,
z.nidename ,
z.direction ,
z.roadtype ,
p.c1,p.c2,p.c3,p.c4,p.c5,p.c6,p.c7
from
(
select r.linkid devicecodeS,
count(r.status) status,
sum(decode(to_char(r.timetag,'yyyy-mm-dd'),'2012-07-11',1,0) c1,
sum(decode(to_char(r.timetag,'yyyy-mm-dd'),'2012-07-12',1,0) c2,
sum(decode(to_char(r.timetag,'yyyy-mm-dd'),'2012-07-13',1,0) c3,
sum(decode(to_char(r.timetag,'yyyy-mm-dd'),'2012-07-14',1,0) c4,
sum(decode(to_char(r.timetag,'yyyy-mm-dd'),'2012-07-15',1,0) c5,
sum(decode(to_char(r.timetag,'yyyy-mm-dd'),'2012-07-16',1,0) c6,
sum(decode(to_char(r.timetag,'yyyy-mm-dd'),'2012-07-17',1,0) c7
from ROADSTATUSHISTORY r
where r.status<=10
group by r.linkid
), p,zlinks z
where z.linkid=p.devicecodeS order by p.devicecodeS asc
#6
提示缺少括号
#1
分开判断吧
select ...
sum(decode(to_char(timetag,'yyyy-mm-dd'),'2012-07-11',1,0) c1,
sum(decode(to_char(timetag,'yyyy-mm-dd'),'2012-07-12',1,0) c2,
...
from tb1
group by ...
#2
能够详细点吗?
#3
时间字段是哪个,没有时间字段,我哪知道哪个状态该放在周几?
#4
r.timetag
#5
select p.devicecodeS ,
z.nodename ,
z.nidename ,
z.direction ,
z.roadtype ,
p.c1,p.c2,p.c3,p.c4,p.c5,p.c6,p.c7
from
(
select r.linkid devicecodeS,
count(r.status) status,
sum(decode(to_char(r.timetag,'yyyy-mm-dd'),'2012-07-11',1,0) c1,
sum(decode(to_char(r.timetag,'yyyy-mm-dd'),'2012-07-12',1,0) c2,
sum(decode(to_char(r.timetag,'yyyy-mm-dd'),'2012-07-13',1,0) c3,
sum(decode(to_char(r.timetag,'yyyy-mm-dd'),'2012-07-14',1,0) c4,
sum(decode(to_char(r.timetag,'yyyy-mm-dd'),'2012-07-15',1,0) c5,
sum(decode(to_char(r.timetag,'yyyy-mm-dd'),'2012-07-16',1,0) c6,
sum(decode(to_char(r.timetag,'yyyy-mm-dd'),'2012-07-17',1,0) c7
from ROADSTATUSHISTORY r
where r.status<=10
group by r.linkid
), p,zlinks z
where z.linkid=p.devicecodeS order by p.devicecodeS asc
#6
提示缺少括号