select的优美句子

09-22 文案句子 投稿:倾诉林

【第1句】: 寻求Sql较经典的select语句案例

精妙Sql语句(总结以前的所有精华) asc 按升序排列desc 按降序排列下列语句部分是Mssql语句,不可以在access中使用。

SQL分类: DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE) DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT) DCL—数据控制语言(GRANT,REVOKE,COMMIT,ROLLBACK)首先,简要介绍基础语句:【第1句】:说明:创建数据库CREATE DATABASE database-name 【第2句】:说明:删除数据库drop database dbname【第3句】:说明:备份sql server--- 创建 备份数据的 deviceUSE masterEXEC sp_addumpdevice 'disk', 'testBack', 'c:\mssql7backup\MyNwind_【第1句】:dat'--- 开始 备份BACKUP DATABASE pubs TO testBack 【第4句】:说明:创建新表create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)根据已有的表创建新表: A:create table tab_new like tab_old (使用旧表创建新表)B:create table tab_new as select col1,col2… from tab_old definition only【第5句】:说明:删除新表drop table tabname 【第6句】:说明:增加一个列Alter table tabname add column col type注:列增加后将不能删除。DB2中列加上后数据类型也不能改变,唯一能改变的是增加varchar类型的长度。

【第7句】:说明:添加主键: Alter table tabname add primary key(col) 说明:删除主键: Alter table tabname drop primary key(col) 【第8句】:说明:创建索引:create [unique] index idxname on tabname(col….) 删除索引:drop index idxname注:索引是不可更改的,想更改必须删除重新建。【第9句】:说明:创建视图:create view viewname as select statement 删除视图:drop view viewname【第10句】:说明:几个简单的基本的sql语句选择:select * from table1 where 范围插入:insert into table1(field1,field2) values(value1,value2)删除:delete from table1 where 范围更新:update table1 set field1=value1 where 范围查找:select * from table1 where field1 like '%value1%' ---like的语法很精妙,查资料!排序:select * from table1 order by field1,field2 [desc]总数:select count as totalcount from table1求和:select sum(field1) as sumvalue from table1平均:select avg(field1) as avgvalue from table1最大:select max(field1) as maxvalue from table1最小:select min(field1) as minvalue from table1【第11句】:说明:几个高级查询运算词A: UNION 运算符 UNION 运算符通过组合其他两个结果表(例如 TABLE1 和 TABLE2)并消去表中任何重复行而派生出一个结果表。

当 ALL 随 UNION 一起使用时(即 UNION ALL),不消除重复行。两种情况下,派生表的每一行不是来自 TABLE1 就是来自 TABLE2。

B: EXCEPT 运算符 EXCEPT 运算符通过包括所有在 TABLE1 中但不在 TABLE2 中的行并消除所有重复行而派生出一个结果表。当 ALL 随 EXCEPT 一起使用时 (EXCEPT ALL),不消除重复行。

C: INTERSECT 运算符INTERSECT 运算符通过只包括 TABLE1 和 TABLE2 中都有的行并消除所有重复行而派生出一个结果表。当 ALL 随 INTERSECT 一起使用时 (INTERSECT ALL),不消除重复行。

注:使用运算词的几个查询结果行必须是一致的。 【第12句】:说明:使用外连接 A、left outer join: 左外连接(左连接):结果集几包括连接表的匹配行,也包括左连接表的所有行。

sql: select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a = b.cB:right outer join: 右外连接(右连接):结果集既包括连接表的匹配连接行,也包括右连接表的所有行。 C:full outer join: 全外连接:不仅包括符号连接表的匹配行,还包括两个连接表中的所有记录。

其次,大家来看一些不错的sql语句【第1句】:说明:复制表(只复制结构,源表名:a 新表名:b) (Access可用) 法一:select * into b from a where 1<>1法二:select top 0 * into b from a 【第2句】:说明:拷贝表(拷贝数据,源表名:a 目标表名:b) (Access可用)insert into b(a, b, c) select d,e,f from b;【第3句】:说明:跨数据库之间表的拷贝(具体数据使用绝对路径) (Access可用)insert into b(a, b, c) select d,e,f from b in '具体数据库' where 条件例子:..from b in '"&Server.MapPath(".")&"\data.mdb" &"' where..【第4句】:说明:子查询(表名1:a 表名2:b)select a,b,c from a where a IN (select d from b ) 或者: select a,b,c from a where a IN (1,2,3)【第5句】:说明:显示文章、提交人和最后回复时间select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b【第6句】:说明:外连接查询(表名1:a 表名2:b)select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a = b.c【第7句】:说明:在线视图查询(表名1:a )select * from (SELECT a,b,c FROM a) T where t.a > 1;【第8句】:说明:between的用法,between限制查询数据范围时包括了边界值,not between不包括select * from table1 where time between time1 and time2select a,b,c, from table1 where a not between 数值1 and 数值【第29句】:说明:in 的使用方法select * from table1 where a [not] in ('值1','值2','值4','值6')【第10句】:说明:两张关联表。

【第2句】: select语句的编辑

要提供Books和 BookType的字段情况

--bookName 书名

--salePrice 销售价格

--price 进货价格

--bookNo 记录编号

1)select * from Books

2) select * from Books

select * from BookType

3) select bookName ,salePrice from Books

4) select bookName , salePrice from Books where bookNo='YBZT0003'

5) selset bookNo as 图书记录编号,bookName as 图书名,price as 进货价格

from books where salePrice=20

6) selcet bookName as 图书的书名,salePrice as 图书的销售价格

from books where salePrice between 10 and 50

7) select bookName from books where bookNmae like '%中%'

8) select bookName from books where aaa like '%人%'

--aaa 代表出版社字段

0

【第3句】: select 语句行查询怎么写

关于select语句的书写,了解执行顺序很有必要,用下面的例子做介绍:

select from where group by having order by 中,

首先执行的是from后的语句,说明数据的来源;

-->;执行where后的语句,对记录进行初步筛选;

-->;执行group by后的语句,对初步筛选后剩下的字段进行分组;

-->;执行having后的语句,对分组后的记录进行二次筛选;

-->;执行select后的语句,在二次筛选后的字段中进行选择并显示出来;

-->;执行order by后的语句,对select 后的字段进行排序。

声明:企算易所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系381046319@qq.com