oracle中如何寫sql把2條合併為一條

時間 2022-04-10 07:10:58

1樓:

--很典型的列轉換為行sql

with temp as --將你的資料建立乙個子查詢,省去建表和插入語句

(select 0 "id", 1 "x", 'a' "y"--帶" "的列名表示區分大小寫

from dual

union all

select 0, 2, 'b' from dual)select "id",

max(decode("x", 1, "x", null)) x1,--使用decode函式,列轉換為行

max(decode("x", 1, "y", null)) y1,max(decode("x", 2, "x", null)) x2,max(decode("x", 2, "y", null)) y2from temp

group by "id"--通過id分組

2樓:匿名使用者

select t1.id,t1.x x1,t1.y y1,t2.x x2,t2.y y2 from t t1, t t2

where t1.id=t2.id and t1.x < t2.x ;

不要動不動都跪求,沒必要,不是很難的東西也,寫的並不好,知道你只是舉個例子,

t1.x < t2.x 代表你根據資料的特殊規律新增的選擇條件,具體你的資料可以改這個條件。

3樓:匿名使用者

select a.id,a.x,a.

y,b.x,b.y from t a join (select * from t) b on a.

id=b.id group by a.id,a.

x,a.y,b.x,b.y

4樓:功若山

select * from (

select id,x x1, lead(x, 1, null) over(partition by id order by x) x2 ,y y1,

lead(y, 1, null) over(partition by id order by y) y2 from table_test)

where x2 is not null

5樓:匿名使用者

select rownum from dual connect by rownum <20;

---以上,希望對你有所幫助。

6樓:匿名使用者

select id,max(x) x1,min(x) x2, max(y) y1, min(y) y2 from table group by id;

7樓:匿名使用者

select

a.id as id,

a.x as x1,

a.y as y1,

b.x as x2,

b.y as y2

from

tb1 a,

tb1 b

where a.id=b.id

試試吧,我忘了這樣會不會有重複出來,如果有的話在select後面加個distinct

oracle中如何用sql實現多條記錄合併成一條記錄?

8樓:匿名使用者

用行列轉換。

select tundishno,sum(decode(strandid,'1', origin,null)) "1",

sum(decode(strandid,'2', origin,null)) "2",

sum(decode(subject,'英語', grade,null)) "3"

......

from table

group by tundishno;

9樓:

行轉列。。。。

select * from (

(select tundishno,origin as a1 from 表 where strandid='1') a,

(select tundishno,origin as a1 from 表 where strandid='2') b,

(select tundishno,origin as a1 from 表 where strandid='3') c,

(select tundishno,origin as a1 from 表 where strandid='4') d,

(select tundishno,origin as a1 from 表 where strandid='5') e,

(select tundishno,origin as a1 from 表 where strandid='6') f

where a.tundishno =b.tundishno and a.

tundishno=c.tundishno and a.tundishno=d.

tundishno

and a.tundishno=e.tundishno and a.tundishno=f.tundishno

)可以按這思路做。。。。

sql 如何將乙個表中的兩條或多條擁有相同id的記錄合併為一條?

10樓:塔莞彌陶然

恐怕要用存貯

程或程式設計實現,

提思路:

1)建立

同欄位結構

新錶table2

2)按col1排序

3)迴圈每條記錄,

記錄每欄位值臨變數

,名vcol1,

vcol2...

if(col1==前

條記錄vcol1)

累加vcol2,

vcol3...(

字串則相連)

else

vcol1,

vcol2...各欄位插入table2

4)終table2應該想要結

如何寫調研方案,如何寫調查方案

調研方案寫法 1 確定好調查目標 不同需要,市場調查的目標有所不同,要調查巨集觀市場環境的發展變化趨勢,尤其要調查所處行業未來的發展狀況 企業制定市場營銷策略時,要調查市場需求狀況,市場競爭狀況,消費者購買行為和營銷要素情況。2 設計調查方案 設計調查方案要包括調查目的要求 調查物件 調查內容 調查...

如何寫情書

就是寫出自己內心的想法,我跟我喜歡的男生就是直接去表白的。可是我相貌平平怎麼讓他對我有好感呢。只要平時多看一眼我就已經足夠了。我想向他表白,不管成功與否都讓他知道,一好姐妹知道我的想法後送我祝願袋,說是在 上一家叫祝你發財的店鋪看到的,在掌櫃範飛和苑英下買的,還是開過光的,希望我能表白成功。真的很神...

如何寫簡歷

個人簡歷可以是 的形式,也可以是其他形式。個人簡歷一般應包括以下幾個方面的內容 1 個人資料 姓名 性別 出生年月 家庭位址 政治面貌 婚姻狀況,身體狀況,興趣 愛好 性格等等 2 學業有關內容 就讀學校 所學專業 學位 外語及計算機掌握程度等等 3 本人經歷 入學以來的簡單經歷,主要是擔任社會工作...

如何寫困難補助申請,如何寫困難補助申請

一 困難補助申請書的適用範圍 困難補助申請書適用下列情況 1.特困學生寫的困難補助申請 在求學期間,由於家庭經濟條件較差,在校學習時交不起學費,或生活上極其困難的學生向學校申請特困補助。這是一項國家專門為在校困難學生發放的一種補助,作為一項工程,它已使許多困難的學生安心地在校讀書學習。2.下崗人員的...

如何寫品質改善措施,品質改善報告如何寫

我以前是生產管理,經常要寫這樣的改善報告。你的情況不明,所以沒辦法幫你寫,但其實很簡單。首先,你要明白乙個道理,讓你寫改善報告並不是追究你的責任,而是讓你這樣的第一當事人想出不讓這樣的事再發生的辦法,以杜絕同樣的事或帶有普遍性類似相同點的事再發生,正所謂 沒有解決不了的問題,只有發現不了的方法!明白...