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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

select语句

發布時間:2023/12/13 综合教程 27 生活家
生活随笔 收集整理的這篇文章主要介紹了 select语句 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

4.1.1 select語句
一、select 查詢語句

1.select [all | distinct] * | 列名1[,列名2,.........,列名n]
from 表名 
[where 條件表達式]
[group by 列名 [asc | desc ] [having 條件表達式]]
[order by 列名 [asc | desc],.....]
[limit  [offset] 記錄數];

4.1.2 查詢列
一、查詢所有列

1.use onlinedb;select * from goodstype;

二、查詢指定的列

1.select gdCode,gdName,gdPrice,gdSaleQty from Goods;

三、計算列值

1.select gdName,gdSaleQty*gdPrice from Goods;
2.select uName, year(now())-year(ubirth) from users;

四、為查詢結果中的列指定列標題

1.select gdName as 商品名,gdPrice as 價格,gdCity as 城市 from Goods;
2.select gdName,gdSaleQty*gdPrice from goods;

4.1.3選擇行
一、使用比較運算符

1.where 表達式1 比較運算符 表達式2
eg: select uID,uName from Users where uID = 8;
eg:select uID,uName,uPhone from Users where year(uBirth)>= 2000;

二、使用邏輯運算符

1.where [not] 表達式1 邏輯運算符 表達式2
eg:select uID,uName,uPhone from Users where year(uBirth) >= 2000 and uSex'男';
eg:select tID,gdname,gdprice from goods where tid=4 or gdprice<=50;
eg:select gdName,gdPrice from goods where not(gdPrice>50);
eg:select gdName,gdPrice,gdCity from goods where gdCity='長沙' or gdCity ='西安' and gdPrice<=50; 

三、使用between and 運算符

1.where 表達式 [not] between 初始值 and 終止值
eg:select gdname,gdprice from goods where gdprice between 100and 500;

四、使用in運算符

1.where 表達式 [not] in (值1,值2,.........)
eg:select gdname,gdcity from  goods where gdcity in ('長沙','西安','上海');

五、使用like運算符

1.where 列名 [not] like '字符串' [escape '轉義字符']
eg:select uname,usex,uphone from users where uname like '李%';
eg:select uname,usex,uphone from users where uname like '_湘%';
eg:select gdname,gdprice,gdcode from goods where gdname '華為P9\_%';
eg:select gdname,gdprice,gdcode from goods where gdname '華為P9|_%' escape '|';

4.1.5 使用limit限制結果集返回的行數

1.limit [offset,] 記錄數
eg:select gdcode,gdname,gdprice from goods limit 3;
eg:select gdcode,gdname,gdprice from goods limit 3,3;

4.1.6數據分組統計
一、使用聚合函數

1.sum/avg/max/min ( [all | distinct ] 列名 | 常量 | 表達式)
eg:select sum(gdsaleqty) from goods;
eg:select max(gdprice) from goods
2.count ( { [ [all | distinct] 列名 | 常量 | 表達式] | * } )
eg: select count(*) from users;
eg: select count(distinct uid) from orders;

二、group by 子句

1.group by [ all ] 列名1, 列名2, [ ,....n] [ with rollup] [having 條件表達式]
eg:select uid,uname,usex,ucity from users group by ucity;
eg:select ucity, count (*) from users group by ucity;
2.group_count([distinct] 表達式 [order by 列名] [sparator 分隔符])
eg:select ucity,group_concat(uid) as uids from users group by ucity;
eg:select ucity,group_concat(uid order by uid separator '_') as uids from users group by ucity;
eg:select ucity,count(*) from users where ucity in ('長沙','上海') group by ucity with rollup;
eg:select ucity ,count(*) from users group by ucity having count (*)>=3;

4.2.1連接查詢

1.select [ALL | DISTINCT ] * | 列名1[,列名2,....,列名n] from 表1 [別名1] JOIN 表2 [別名2] [on 表1.關系列 = 表2.關系列 | using(列名)][where 表達式]

4.2.2內連接

1.select tname,gdcode,gdname,gdprice from goodstype JOIN goods on goodstype.tid = goods.tid where tname = '服飾';

總結

以上是生活随笔為你收集整理的select语句的全部內容,希望文章能夠幫你解決所遇到的問題。

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