日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

数据库-多条件查询-优先级

發布時間:2024/4/13 数据库 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 数据库-多条件查询-优先级 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

多條件查詢(and | or)?

mysql> SELECT * FROM pet WHERE species = 'dog' AND sex = 'f'; +‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐+ | name | owner | species | sex | birth | death | +‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐+ | Buffy | Harold | dog | f | 1989‐05‐13 | NULL | +‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐+ mysql> SELECT * FROM pet WHERE species = 'snake' OR species = 'bird'; +‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐+ | name | owner | species | sex | birth | death | +‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐+ | Chirpy | Gwen | bird | f | 1998‐09‐11 | NULL | | Whistler | Gwen | bird | NULL | 1997‐12‐09 | NULL | | Slim | Benny | snake | m | 1996‐04‐29 | NULL | +‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐+

優先執行括號中的邏輯

mysql> SELECT * FROM pet WHERE (species = 'cat' AND sex = 'm') ‐> OR (species = 'dog' AND sex = 'f'); +‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐+ | name | owner | species | sex | birth | death | +‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐+ | Claws | Gwen | cat | m | 1994‐03‐17 | NULL | | Buffy | Harold | dog | f | 1989‐05‐13 | NULL | +‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐+

檢索特定的列

mysql> SELECT name, birth FROM pet; +‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+ | name | birth | +‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+ | Fluffy | 1993‐02‐04 | | Claws | 1994‐03‐17 | | Buffy | 1989‐05‐13 | | Fang | 1990‐08‐27 | | Bowser | 1989‐08‐31 | | Chirpy | 1998‐09‐11 | | Whistler | 1997‐12‐09 | | Slim | 1996‐04‐29 | | Puffball | 1999‐03‐30 | +‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+

查詢不重復的字段要使用關鍵詞DISTINCT?

mysql> SELECT DISTINCT owner FROM pet; +‐‐‐‐‐‐‐‐+ | owner | +‐‐‐‐‐‐‐‐+ | Benny | | Diane | | Gwen | | Harold | +‐‐‐‐‐‐‐‐+

可以使用組合條件查詢特定的列

mysql> SELECT name, species, birth FROM pet ‐> WHERE species = 'dog' OR species = 'cat'; +‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+ | name | species | birth | +‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+ | Fluffy | cat | 1993‐02‐04 | | Claws | cat | 1994‐03‐17 | | Buffy | dog | 1989‐05‐13 | | Fang | dog | 1990‐08‐27 | | Bowser | dog | 1989‐08‐31 | +‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐+

?

總結

以上是生活随笔為你收集整理的数据库-多条件查询-优先级的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。