全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:683
推到 Plurk!
推到 Facebook!

由detail的資料更新master

尚未結案
danajn
一般會員


發表:14
回覆:29
積分:8
註冊:2002-08-01

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-05-28 10:29:07 IP:211.75.xxx.xxx 未訂閱
若detail的a欄位值皆為y時 則將master的b欄位才更新為Y 請問sql該如何下.. thx.
hua2000
中階會員


發表:102
回覆:200
積分:65
註冊:2006-11-04

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-05-28 12:14:14 IP:218.20.xxx.xxx 未訂閱
一定要用SQL嗎? 用程序不難的喲!
danajn
一般會員


發表:14
回覆:29
積分:8
註冊:2002-08-01

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-05-28 12:45:54 IP:211.75.xxx.xxx 未訂閱
只要可以更新至TABLE就行啦... 那請問... 程序要怎麼用呢...^^"...
timhuang
尊榮會員


發表:78
回覆:1815
積分:1608
註冊:2002-07-15

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-05-28 13:02:35 IP:203.95.xxx.xxx 未訂閱
引言: 若detail的a欄位值皆為y時 則將master的b欄位才更新為Y 請問sql該如何下..
假設 detail 和 master 的 relation 是一個訂單編號的欄位 (orderid) 的話, 你可以這樣下: update master set b='Y' where not exists (select * from detail where detail.orderid=master.orderid and (detail.a <> 'y' or detail.a is null)) --以下條件為確保沒有 detail 的 master 資料處理是否也是要更新為 'Y' and exists (select * from detail where detail.orderid=master.orderid and detail.a = 'y')
timhuang
尊榮會員


發表:78
回覆:1815
積分:1608
註冊:2002-07-15

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-05-28 13:05:11 IP:203.95.xxx.xxx 未訂閱
也可以使用 count 的方式, 這樣下 update master set b='Y' where (select count(*) from detail where detail.orderid=master.orderid and detail.a='y') = (select count(*) from detail where detail.orderid=master.orderid ) --以下條件為確保沒有 detail 的 master 資料處理是否也是要更新為 'Y' and (select count(*) from detail where detail.orderid=master.orderid ) <> 0
longsanglin
初階會員


發表:10
回覆:57
積分:43
註冊:2002-04-23

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-05-28 13:11:25 IP:211.22.xxx.xxx 未訂閱
引言: 只要可以更新至TABLE就行啦... 那請問... 程序要怎麼用呢...^^"...
1.用程序 a.設一變數 b.跑detail資料迴圈計算a欄位不等於y c.判斷該變數為0時, 即更新Master的b欄位 2.用SQL update MasterTable set b='y' where Masterkey=Detailkey and 0=(select count(*) from DetailTable where a<>'y') 發表人 - longsanglin 於 2003/05/28 13:13:30
系統時間:2024-05-18 12:56:43
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!