先學習NOT(邏輯非)用法。正則表達式
#查詢StudentBirthday非空列 SELECT * FROM "public"."Students" WHERE "StudentBirthday" IS NOT NULL; #注意對比兩個語句查詢結果 SELECT "StudentBirthday" FROM "public"."Students" WHERE "StudentBirthday" IS NOT NULL;
排除非條件值學習
#不查詢StudentSalary=2值 SELECT * FROM "public"."Students" WHERE "StudentSalary" NOT IN('2'); #對比查詢語句 SELECT "StudentName","StudentAddress" FROM "public"."Students" WHERE "StudentSalary" NOT IN('2');
LIKE支持模糊查詢,LIKE與兩個通配符(%與_)一塊兒使用,百分號表示零個,一個或多個字符。下劃線表明一個單一字符。通配符能夠被組合使用。ILIKE和LIKE 相似,LIKE區分大小寫,ILIKE不區分。SIMILAR TO和LIKE有類似性,不事後者支持模糊查詢同時還支持正則表達式。code
先插入兩條數據用於練習。class
INSERT INTO "Students" VALUES (13, '杜牧', '0803-1-1', '陝西省西安市', 3); INSERT INTO "Students" VALUES (14, '李商隱', '0817-1-1', NULL, NULL);
#查詢全部杜姓人名,匹配單個字符 SELECT * FROM "public"."Students" WHERE "StudentName" LIKE '杜_'; #匹配多個字符,本例匹配StudentAddress列中含有陝西查詢結果 SELECT "StudentName","StudentAddress" FROM "public"."Students" WHERE "StudentAddress" LIKE '%陝西%';