测试需要知道的9条基本sql语句
admin
2023-05-02 14:44:00
0

1、测试需要学习简单的基本的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
2、说明:复制表(只复制结构,源表名:a 新表名:b) (Access可用)
法一:select
into b from a where 1<>1(仅用于SQlServer)
法二: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、说明:外连接查询(表名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

6、说明:两张关联表,删除主表中已经在副表中没有的信息
delete from table1 where not exists ( select * from table2 where table1.field1=table2.field1 )

7、说明:四表联查问题:
select * from a left inner join b on a.a=b.b right inner join c on a.a=c.c inner join d on a.a=d.d where .....

8、说明:一条sql 语句搞定数据库分页
select top 10 b.* from (select top 20 主键字段,排序字段 from 表名 order by 排序字段 desc) a,表名 b where b.主键字段 = a.主键字段 order by a.排序字段

9、说明:列出数据库里所有的表名
select name from sysobjects where type='U' // U代表用户

相关内容

热门资讯

国家数据局:支持地方通过“以数... 记者从国家数据局了解到,“数据要素×”城市行活动今天在南京启动,国家层面将支持各地积极挖...
河南多地出现巨大“不明飞行物”... 5月12日晚8点左右,安阳、新乡、焦作……河南多地夜空中出现一团发光“水母云”。这到底是什么东西呢?...
外交部:中方欢迎特朗普总统对中... 5月13日,外交部发言人郭嘉昆主持例行记者会。有记者就美国总统特朗普访华行前的相关言论提问。郭嘉昆表...
外交部质问日本右翼势力:是要打... 外交部:日本重走军国主义的回头路是一条不归路5月13日,外交部发言人郭嘉昆主持例行记者会。有记者问:...
2025年许昌市国民经济和社会... 【大河财立方消息】 5月12日,许昌市统计局、国家统计局许昌调查队发布2025年许昌市国民经济和社会...
我国首条深水油气装备工艺管线智... (来源:中国水运网) 转自:中国水运网 5月10日,海洋石油工程股份有限公司(简称“海油工程”)发布...
成都中科唯实申请一种真空蝶阀专... 国家知识产权局信息显示,成都中科唯实仪器有限责任公司申请一项名为“一种真空蝶阀”的专利,公开号CN1...
华为充电宝怎么样?西圣、图拉斯... 现如今市面上的选择可见是越来越多了,但“踩雷”情况也很常见:有的看起来容量大、实际给手机充电虚标非常...
智己汽车充电地图接入华为超充 ... 【CNMO科技消息】5月13日,智己汽车宣布,华为超充已正式上线其充电地图服务。即日起,智己用户可通...
爆火短剧《enemy》导演否认... 近日,短剧《enemy》凭借震撼人心的台词与浓烈的家国情怀爆火出圈。据钱江视频,5月13日,《ene...