Oracle多行資料合併

2021-06-08 06:33:24 字數 1050 閱讀 6684

1. 多個未知數值合併

selectoperate_id, max(substr(phone_id, 2)) phone_id

from (select operate_id, sys_connect_by_path(phone_id, ',') phone_id

from (select operate_id,

phone_id,

operate_id || rn rchild,

operate_id || (rn - 1)***ther

from (selecttest.operate_id,

test.phone_id,

row_number()over(partition by test.operate_id order by test.phone_id) rn

from lq_card_infotest))

connect by prior rchild = ***ther

start with ***ther like '%0')

group by operate_id

解析:其中operate_id是要被分組的字段,phone_id是要被展示的字段

2. 一定小範圍已知資料合併

select t.operate_id,

sum(case when t.phone_id='18937278888' then t.phone_id end) no1,

sum(case when t.phone_id='13303723322' then t.phone_id end) no2,

sum(case when t.phone_id='18937245684' then t.phone_id end) no3,

sum(case when t.phone_id='13323729424' then t.phone_id end) no4

from lq_card_info t  group by t.operate_id order by t.operate_id

解析:其中operate_id是要被分組的字段,phone_id是要被展示的字段

MySQL 多行資料合併 GROUP CONCAT

表結構及資料 drop table if exists course create table course id int 11 not null,name varchar 50 default null comment 姓名 course name varchar 50 default null ...

MySQL 多行資料合併 GROUP CONCAT

表結構及資料 drop table if exists course create table course name varchar 255 character set utf8 collate utf8 general ci default null,course name varchar 25...

oracle中update多行資料

a表aid,aname b表bid,bname 現在假設兩張表裡面的資料行數是相等的,現在要更新a表裡面的每一行的anmae,條件是依據b表裡面的bid 在sql server中好像可以這麼寫 update a set aname b.bname from a a,b b where a.aid b...