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

歡迎訪問 生活随笔!

生活随笔

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

数据库

mysql select 使用_mysql select简单用法

發布時間:2024/1/23 数据库 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql select 使用_mysql select简单用法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

mysql select簡單用法 1、select語句可以用回車分隔 $sql=select * from article where id=1 和 $sql=select * from article where id=1,都可以得到正確的結果,但有時分開寫或許能更明了一點,特別是當sql語句比較長時 2、批量查詢數據 可以用in來實現 $sql

mysql select簡單用法

1、select語句可以用回車分隔

$sql="select * from article where id=1"

$sql="select * from article

where id=1",都可以得到正確的結果,但有時分開寫或許能更明了一點,特別是當sql語句比較長時

2、批量查詢數據

可以用in來實現

$sql="select * from article where id in(1,3,5)"

3、使用concat連接查詢的結果

$sql="select concat(id,"-",con) as res from article where id=1"

返回"1-article content"

4、使用locate

用法:

select locate("hello","hello baby");返回1

不存在返回0

5、使用group by

以前一直沒怎么搞明group by 和 order by,其實也滿簡單的,group by 是把相同的結果編為一組

exam:$sql="select city ,count(*) from customer group by city";

這句話的意思就是從customer表里列出所有不重復的城市,及其數量(有點類似distinct)

group by 經常與AVG(),MIN(),MAX(),SUM(),COUNT()一起使用

6、使用having

having 允許有條件地聚合數據為組

$sql="select city,count(*),min(birth_day) from customer

group by city having count(*)>10";

這句話是先按city歸組,然后找出city地數量大于10的城市

btw:使用group by + having 速度有點慢

同時having子句包含的表達式必須在之前出現過

7、組合子句

where、group by、having、order by(如果這四個都要使用的話,一般按這個順序排列)

8、使用distinct

distinct是去掉重復值用的

$sql="select distinct city from customer order by id desc";

這句話的意思就是從customer表中查詢所有的不重復的city

9、使用limit

如果要顯示某條記錄之后的所有記錄

$sql="select * from article limit 100,-1";

10、多表查詢

$sql="select user_name from user? u,member? m

where u.id=m.id and

m.reg_date>=2006-12-28

order by u.id desc"

注意:如果user和member兩個標同時有user_name字段,會出現mysql錯誤(因為mysql不知道你到底要查詢哪個表里的user_name),必須指明是哪個表的;

總結

以上是生活随笔為你收集整理的mysql select 使用_mysql select简单用法的全部內容,希望文章能夠幫你解決所遇到的問題。

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