久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何檢查父母的id-s然后設置值

How to check id-s of parents and then set value(如何檢查父母的id-s然后設置值)
本文介紹了如何檢查父母的id-s然后設置值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有這樣的桌子:

ID  object_id    parent_id   allowed
1       1           0           0   
2       23          25          1
3       25          44          0       
4       44          38          0       
5       38          1           0
6       52          55          1           
7       55          58          0
8       58          60          0
9       60          1           0

現在想要選擇 row-s where allowed = 1 然后為我選擇的行的父級設置 allowed = 1.例如它會像:

Now want select row-s where allowed = 1 and then set allowed = 1 for parents of the row which i select. For example it will be like :

步驟 1. select object_id , parent_id from myTbl where allowed = 1 顯示:

ID  object_id    parent_id   allowed
2       23          25          1   
6       52          55          1

第 2 步:檢查 object_id 是否是 IN 上面結果中的 parent_id 并設置 allowed = 1 當 object_id 等于任何 parent_id 時.

step 2: It checks if the object_id is IN the parent_id from the above result and sets allowed = 1 when the object_id is equal to any of the parent_id's.

重復完全相同的 step2,直到到達 object_idparent_id

The exact same step2 repeats until it reaches a point where there is no match between object_id and parent_id

ID  object_id    parent_id   allowed
2       23          25          1   
6       52          55          1
3       25          44          0 --update to 1
7       55          58          0 -- update to 1

完全相同的原則也適用于以下記錄:

The exact same principle is being applied to the folling records, too:

對于 25,44,1 - 44,38,0 (allowed is 0 want set 1) 當 set allowed = 1 時44,38,1

for 25,44,1 - 44,38,0 (allowed is 0 want set 1) when set allowed = 1 it will be 44,38,1

對于 55,58,1 - 58,60,0 (allowed is 0 want set 1) 當 set allowed = 1 時58,60,1

for 55,58,1 - 58,60,0 (allowed is 0 want set 1) when set allowed = 1 it will be 58,60,1

怎么做?在表中,我的表包含多個狀態為 allowed=1 的記錄,并且在此特定示例中僅使用了其中的 2 個.

How to do it ? In table My table contains multiple records with status allowed=1 and only 2 of them are used in this particular example.

推薦答案

嘗試:

UPDATE tbl 
SET    allowed = 1 
FROM   (SELECT * 
        FROM   tbl 
        WHERE  allowed = 0) A 
        INNER JOIN 
        (SELECT * 
            FROM   tbl                 
            WHERE  allowed = 1) B 
        ON A.objectid = B.parentid 

這篇關于如何檢查父母的id-s然后設置值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Modify Existing decimal places info(修改現有小數位信息)
The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關名稱“CONVERT)
T-SQL left join not returning null columns(T-SQL 左連接不返回空列)
remove duplicates from comma or pipeline operator string(從逗號或管道運算符字符串中刪除重復項)
Change an iterative query to a relational set-based query(將迭代查詢更改為基于關系集的查詢)
concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
主站蜘蛛池模板: 欧美一区二区三区,视频 | 999久久久久久久久6666 | 美女视频网站久久 | 天天操天天拍 | 怡红院怡春院一级毛片 | 有码在线 | 亚洲国产精品一区二区三区 | 一级黄色毛片子 | 色综合久| 精品亚洲一区二区三区四区五区 | 91在线视频播放 | 成人av资源在线 | 天堂资源视频 | 精品久久久久国产免费第一页 | 欧洲成人午夜免费大片 | 日韩精品一区二区三区中文在线 | av在线播放国产 | 成人av鲁丝片一区二区小说 | 国产资源网 | 国产精品欧美一区二区 | 国产成人网 | 四虎成人av | 日韩一区二区在线视频 | 中文字幕一区二区三区四区五区 | 久久久久亚洲 | 欧美日韩在线高清 | 欧美成视频 | 精品一区二区三区中文字幕 | 国产视频三区 | 国产精品视频在线观看 | 成年人在线观看视频 | 国产精品久久久久久久久久三级 | 91精品国产美女在线观看 | 韩日一区二区三区 | 日韩精品欧美精品 | 久久精品网| 玖玖综合网 | 欧美精品一区二区三区四区五区 | 欧美一区二区在线看 | 欧美在线一区视频 | 国产欧美视频一区二区三区 |