select chgdetail_id,
chgdetail_custname
min(decode(seq, 1, serv_devcode, NULL)) || ',' ||
min(decode(seq, 2, serv_devcode, NULL)) || ',' ||
min(decode(seq, 3, serv_devcode, NULL))
chgdetail_roperatorid
from (select chgdetail_id,
chgdetail_custname,
serv_devcode,
row_number() over(partition by chgdetail_id order by chgdetail_id asc) seq
from (select c.id chgdetail_id,
c.custname chgdetail_custname,
serv.devcode serv_devcode
from chgdetail c
left outer join serv serv on c.racctid = serv.racctid
where
group by c.id,
c.custname,
serv.devcode))
where seq < 4
group by chgdetail_id,
chgdetail_custname
SQL说明:当查询出结果的相连的数量(如上SQL只要求电话号前三位通过“,”相连)有限制或相同需求时,可用decode相连。
---------------------------------------------------------------------------------------------------------------------------------
说人之短,乃护己之短。夸己之长,乃忌人之长。皆由存心不厚,识量太狭耳。能去此弊,可以进德,可以远怨。
http://www.blogjava.net/szhswl
------------------------------------------------------------------------------------------------------ ----------------- ---------
posted on 2007-12-03 15:42
宋针还 阅读(172)
评论(0) 编辑 收藏 所属分类:
SQL