SQL语句大全 珍藏版2019-02-28

上传者: szm1900 | 上传时间: 2022-06-25 17:13:30 | 文件大小: 1.13MB | 文件类型: RAR
目 录 (01) SELECT .................................. ............... .......................................2 查找 SELECT "栏位名" FROM "表格名" (02) DISTINCT................................. ............... .....................................2 不同值 SELECT DISTINCT "栏位名" FROM "表格名" (03) WHERE...................................... ............... ....................................2 条件 SELECT "栏位名" FROM "表格名" WHERE "条件" (04) AND OR ...................................... ............... ..................................3 条件并和或 SELECT "栏位名" FROM "表格名" WHERE "简单条件" {[AND|OR] "简单条件"} (05) IN .............................................. ............... ..................................3 包含 SELECT "栏位名" FROM "表格名" WHERE "栏位名" IN ('值一', '值二 ', ...) (06) BETWEEN.............................. ............... ........................................4 范围包含 SELECT "栏位名" FROM " 表格名" WHERE "栏位名" BETWEEN '值一' AND '值二' (07) LIKE....................................... ............... .......................................4 通配符包含 SELECT "栏位名" FROM "表格名" WHERE "栏位名" LIKE {套 式} -- 支持通配符‘_’ 单个字符 '%' 任意字符 (08) ORDER BY............................... ............... ......................................5 排序 SELECT "栏位名" FROM "表格名" [WHERE "条件"] ORDER BY "栏位 名" [ASC, DESC] -- ASC 小到大 DESC 大到小 (09) 函数........................................ ............... ......................................5 函数 AVG (平均) COUNT (计数) MAX (最大值) MIN (最小值) SUM (总合) SELECT "函数名"("栏位名") FROM "表格名" (10) COUNT .................................... .............. ......................................6 计 数 SELECT COUNT(store_name) FROM Store_Information WHERE store_name is not NULL -- 统计非空 SELECT COUNT(DISTINCT store_name) FROM Store_Information -- 统计多 少个不同 (11) Group By .................................. .............. .....................................6 字段分组 SELECT "栏位 1", SUM("栏位 2") FROM "表格名" GROUP BY " 栏位 1" (12) HAVING...................................... .............. ....................................7 函数条件定位 SELECT "栏位 1", SUM("栏位 2") FROM "表格名" GROUP BY "栏位 1" HAVING (函数条件) (13) ALIAS........................................... .............. ..................................7 别名 SELECT "表格别名"."栏位 1" "栏位别名" FROM "表格名" "表格别名" (14) 连接................................................ ..............................................8 SELECT A1.region_name REGION, SUM(A2.Sales) SALES FROM Geography A1, Store_Information A2 WHERE A1.store_name = A2.store_name GROUP BY A1.region_name (15) 外部连接........................................... ............................................9 SELECT A1.store_name, SUM(A2.Sales) SALES FROM Georgraphy A1, Store_Information A2 WHERE A1.store_name = A2.store_name (+) GROUP BY A1.store_name (16) Subquery .............................. .............. .........................................9 嵌套 SELECT "栏位 1" FROM "表格" WHERE "栏位 2" [比较运算素] (SELECT "栏位 1" FROM "表格" WHERE (17) UNION.................................... ............... ......................................10 合并不重复结果 [SQL 语句 1] UNION [SQL 语句 2] (18) UNION ALL....................................... .............. ............................ 11 合并所有结果 [SQL 语句 1] UNION ALL [SQL 语句 2] (19) INTERSECT..................................................... ............... ............. 11 查找相同值 [SQL 语句 1] INTERSECT [SQL 语句 2] (20) MINUS............................ ............... ..............................................12 显示第一个语句中不在第二个语句中的项 [SQL 语句 1] MINUS [SQL 语句 2] (21) Concatenate................................... ............... ...............................12 结果相加(串联) MySQL/Oracle: SELECT CONCAT(region_name,store_name) FROM Geography WHERE store_name = 'Boston'; SQL Server: SELECT region_name + ' ' + store_name FROM Geography WHERE store_name = 'Boston'; (22) Substring ...................................................... ............... ...............13 取字符 SUBSTR(str,pos) SUBSTR(str,pos,len) (23) TRIM ...... .............. .....................................................................14 去空 SELECT TRIM(' Sample '); TRIM()首尾, RTRIM()首, LTRIM()尾 (24) Create Table ........... .............. .....................................................14 建立表格 CREATE TABLE "表格名"("栏位 1" "栏位 1 资料种类","栏位 2" "栏位 2 资料种类",... ) (25) Create View............................. .............. ......................................15 建立表格视观表 CREATE VIEW "VIEW_NAME" AS "SQL 语句" (26) Create Index........................................... ............... ......................16 建立索引 CREATE INDEX "INDEX_NAME" ON "TABLE_NAME" (COLUMN_NAME) (27) Alter Table.. .............. ..................................................................16 修改表 ALTER TABLE "table_name"[改变方式] -- ADD 增加;DROP 删 除;CHANGE 更名;MODIFY 更改类型 (28) 主键.......................... ..................................................................18 ALTER TABLE Customer ADD PRIMARY KEY (SID) (29) 外来主键....................................... ............ ..................................18 CREATE TABLE ORDERS(Order_ID integer,Order_Date date,Customer_SID integer,Amount double,Primary Key (Order_ID),Foreign Key (Customer_SID) references CUSTOMER(SID)); (30) Drop Table................................................. ............... ...................19 删除表 DROP TABLE "表格名" (31) Truncate Table ................. ............... ............................................20 清除表内容 TRUNCATE TABLE "表格名" (32) Insert Into....................................... ............... .............................20 插入内容 INSERT INTO "表格名" ("栏位 1", "栏位 2", ...) VALUES ("值 1", "值 2", ...) (33) Update ........................ ................ ................................................20 修改内容 UPDATE "表格名" SET "栏位 1" = [新值] WHERE {条件} (34) Delete ......................................... .............. .................................21 DELETE FROM "表格名" WHERE {条件}

文件下载

资源详情

[{"title":"( 1 个子文件 1.13MB ) SQL语句大全 珍藏版2019-02-28","children":[{"title":"SQL语句大全 珍藏版20190228.pdf <span style='color:#111;'> 1.52MB </span>","children":null,"spread":false}],"spread":true}]

评论信息

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明