久久久久久久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)
主站蜘蛛池模板: 日韩一区二区三区av | 亚洲午夜视频 | 久久久国产精品视频 | 1区2区3区视频 | 在线观看黄色电影 | 99精品九九| 中文字幕 在线观看 | 久久久蜜桃 | 亚洲精品久久久久中文字幕二区 | 欧美精品一区二区三区四区 在线 | 日韩视频精品在线 | 国产欧美在线一区二区 | 日韩一区二区福利视频 | 欧美精品在线一区二区三区 | jav成人av免费播放 | 欧美色人| 在线看亚洲| 久久天天躁狠狠躁夜夜躁2014 | 欧美日产国产成人免费图片 | 国产精品视频网站 | 亚洲成人av在线 | 黑人巨大精品欧美一区二区免费 | 无码日韩精品一区二区免费 | 精品亚洲一区二区三区 | 亚洲不卡视频 | 欧美 中文字幕 | 欧美色欧美亚洲另类七区 | 成人精品毛片国产亚洲av十九禁 | 日韩成人精品在线观看 | 日韩不卡三区 | 久久久久久综合 | 国产精品福利一区二区三区 | 成人在线观看免费视频 | 亚州春色 | 99精品电影| 久国产视频| 成人视屏在线观看 | 91久久久久久 | 精品国产99 | 国精久久 | 欧洲亚洲一区二区三区 |