首頁>技術>

本篇內容只說查詢,用簡單的示例加結果的方式,讓大家一看便懂。

---基本測試表:請一定先看一下表,再看語句

表一:select * from t_step;

表二:select * from t_case;

條件運算一: =、!=、>、<、>=、<=、not、and、or
select * from t_step where case_id = 'case001';返回:1條資料id    case_id      step---------------1	    case001	    步驟1select * from t_step where case_id != 'case001';返回:4條資料id    case_id      step---------------2	   case002	   步驟23	   case003	   步驟34	   case004	   步驟45	   case002	   步驟22select * from t_step where case_id = 'case001' and step = '步驟1';返回:1條資料id    case_id      step----------------1	    case001	    步驟1select * from t_step where case_id = 'case001' or step = '步驟2';返回:1條資料id    case_id      step ----------------1	    case001	    步驟12	    case002	    步驟2
條件運算二:is null、is not null;in 、not in
select * from t_step where case_id is null;返回:0條資料id    case_id      step----------------select * from t_step where case_id is not null;返回:5條資料id    case_id      step----------------1	   case001	   步驟12	   case002	   步驟23	   case003	   步驟34	   case004	   步驟45	   case002	   步驟22select * from t_step where case_id in ('case001','case002');返回:3條資料id    case_id      step----------------1	   case001	   步驟12	   case002	   步驟25	   case002	   步驟22select * from t_step where case_id not in ('case001','case002');返回:2條資料id    case_id      step----------------3	   case003	   步驟34	   case004	   步驟4
條件運算三:like、not like;between and 、not between and
select * from t_step where case_id like '%002';返回:2條資料  解讀:以 【002】 結尾的id    case_id      step----------------2	   case002	   步驟25	   case002	   步驟22select * from t_step where step like '步驟2%';返回:2條資料  解讀:以 【步驟2】 開頭的id    case_id      step----------------2	   case002	   步驟25	   case002	   步驟22select * from t_step where step like '%步驟2%';返回:2條資料  解讀:包含【步驟2】的id    case_id      step----------------2	   case002	   步驟25	   case002	   步驟22select * from t_step where id between 1 and 3;返回:3條資料  解讀:id 在 1到3之間的id    case_id      step----------------1	   case001	   步驟12	   case002	   步驟23	   case003	   步驟3select * from t_step where id not between 1 and 3;返回:2條資料  解讀:id 不在 1到3之間的id    case_id      step----------------4	   case004	   步驟45	   case002	   步驟22

本來也要介紹sql 查詢語句的,一看太多了,下篇介紹吧,也不希望浪費小夥伴們的時間。

總結的東西儘量 1分鐘之內能看完,看懂!

13
最新評論
  • BSA-TRITC(10mg/ml) TRITC-BSA 牛血清白蛋白改性標記羅丹明
  • 「leetcode」貪心演算法經典題目:分發糖果