sql的與運算

2021-09-10 22:48:41 字數 471 閱讀 2124

當資料庫中要用乙個數值型資料來儲存多個類目型數值時,可以用二進位制的方式來儲存,如以下物件

"窖底井":[,,

,

表示思路:例如當既有雜物,又有出口堵塞時,資料庫用2+4=6表示,因此當根據數字判斷包含哪些專案時,就需要用到與運算了,運算方法如下(well為屬性名):

case when bitand(well,1)=1 then 1 else 0 end//完好,和1與的結果=1

case when bitand(well,2)=2 then 1 else 0 end//有雜物,和2與的結果=2

case when bitand(well,4)=4 then 1 else 0 end//出口堵塞,和4與的結果=4

case when bitand(well,8)=8 then 1 else 0 end//與窖底溝連通異常,和8與的結果=8

sql的集合運算

交集 內連線 並集全外連線 有的dbms不支援全外連線,比如mysql,可以使用union all來實現全外連線 select from table a inner join table b on table a.id table b.id union allselect from table a ...

SQL集合運算

集合運算是對輸入的兩個或多個集合進行的運算,最終輸出乙個結果集。t sql支援3種集合運算 並集 union 交集 intersect 和差集 except 集合運算的基本格式為 輸入的集合1 集合運算 輸入的集合2 order by 需要注意的是,集合運算涉及的兩個查詢不能包含order by 子...

SQL集合運算

1.表的加減法 1 定義 集合在數學領域表示 各種各樣的事物的總和 在資料庫領域表示記錄的集合.具體來說,表 檢視和查詢的執行結果都是記錄的集合,其中的元素為表或者查詢結果中的每一行。在標準 sql 中,分別對檢索結果使用union,intersect,except來將檢索結果進行並,交和差運算,像...