請教SQL指令如何下? |
尚未結案
|
Mecer
初階會員 ![]() ![]() 發表:15 回覆:30 積分:29 註冊:2002-10-25 發送簡訊給我 |
|
Fishman
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:120 回覆:1949 積分:2163 註冊:2006-10-28 發送簡訊給我 |
|
Mecer
初階會員 ![]() ![]() 發表:15 回覆:30 積分:29 註冊:2002-10-25 發送簡訊給我 |
|
Fishman
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:120 回覆:1949 積分:2163 註冊:2006-10-28 發送簡訊給我 |
Hi: Oracle 語法如下,你可以試試
select distinct 0 id, m0.item_id, count(distinct d0.subitem_id) from test_detail d0, test_master m0 where m0.id = d0.master_id group by m0.id, m0.item_id having count(distinct d0.subitem_id) = (select count(distinct d1.subitem_id) from test_detail d1, test_master m1 where m1.id = d1.master_id and m1.item_id = m0.item_id group by m1.item_id) union all select distinct m0.id, m0.item_id, count(distinct d0.subitem_id) from test_detail d0, test_master m0 where m0.id = d0.master_id group by m0.id, m0.item_id having count(distinct d0.subitem_id) != (select count(distinct d1.subitem_id) from test_detail d1, test_master m1 where m1.id = d1.master_id and m1.item_id = m0.item_id group by m1.item_id)
------
Fishman |
Fishman
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:120 回覆:1949 積分:2163 註冊:2006-10-28 發送簡訊給我 |
Hi:
你可以在 Database 中寫一個 Function,傳入值為 Master 之 id 值,回傳值為該 id 之 Subitem_ID 之字串值 例如傳入值為 1 則回傳值為 111213,亦即將 Subitem_ID 轉會為文字後相加(須注意排序問題) 傳入值為 2 則回傳值為 111213 傳入值為 3 則回傳值為 2021 傳入值為 4 則回傳值為 202122 再於 SQL Command 中 select distinct item_id, get_subitem_id_str(id) as subitem_id_str from master 希望對你幫助,若有問題,請再告知
------
Fishman |
jeffreck
高階會員 ![]() ![]() ![]() ![]() 發表:247 回覆:340 積分:197 註冊:2003-01-23 發送簡訊給我 |
另一種作法,不知是不是你要的
SELECT Temp.Item_ID, Temp.筆數
FROM (
SELECT Master.Item_ID, Detail.SubItem_ID, Count(Detail.Master_ID) AS 筆數
FROM Master INNER JOIN Detail ON Master.ID=Detail.Master_ID
GROUP BY Master.Item_ID, Detail.SubItem_ID) as Temp GROUP BY Temp.Item_ID, Temp.筆數;
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |