日期:2014-05-18  浏览次数:20457 次

跪求高手解答,非常着急!!!!!!
id prev_Id seat_no seat_type mark sellwind
196 888 1 15 1 20
197 999 2 15 1 20

上面除seat_no列外分成两行,其他列合并成一行,第二行只显示seat_no为2,第二行其他列为空

------解决方案--------------------
id,也能相加?
------解决方案--------------------
SQL code

create table t3 (id int, prev_Id int, seat_no int, seat_type int, mark int, sellwind int)

insert into t3
select 196, 888, 1, 15, 1, 20 union all
select 197, 999, 2, 15, 1, 20

select * from t3

id          prev_Id     seat_no     seat_type   mark        sellwind
----------- ----------- ----------- ----------- ----------- -----------
196         888         1           15          1           20
197         999         2           15          1           20

select 
(a.id+b.id) id,
(a.prev_Id+b.prev_Id) prev_Id,
a.seat_no,
(a.seat_type+b.seat_type) seat_type,
(a.mark+b.mark) mark,
(a.sellwind+b.sellwind) sellwind
from t3 a
left join t3 b on a.seat_no=b.seat_no-1

id          prev_Id     seat_no     seat_type   mark        sellwind
----------- ----------- ----------- ----------- ----------- -----------
393         1887        1           30          2           40
NULL        NULL        2           NULL        NULL        NULL