有关数据库select的所有语句用法?以及所有查询语句?

有关数据库select的所有语句用法?以及所有查询语句?,第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%’ (所有包含‘value1’这个模式的字符串)---like的语法很精妙,查资料! 排序:select * from table1 order by field1,field2 [desc] 分组:select * from table1 group by field1 ORDER BY count(ShopId) LIMIT 20 (兼并排序分页) 总数: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[separator] 查询去除重复值:select distinct * from table1 使用外连接 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.c B:right outer join: 右外连接(右连接):结果集既包括连接表的匹配连接行,也包括右连接表的所有行。 C:full outer join: 全外连接:不仅包括符号连接表的匹配行,还包括两个连接表中的所有记录。

麻烦采纳,谢谢!

select * from 表名 where 条件 //查询所有的列

select 列名,列名。。。 from 表名 where 条件 //查询指定的列

select 列名 as 别名(虚表上显示的列名),列名。。。 from 表名 //查询出来的虚表上的列名显示为别名

select t.列名,t.列名。。 from 表名 as t //给表取别名

select count(*) from 表名 //使用函数查询(count(返回行数),avg(平均值。。。))

declare @tab table(id int,dt Date,num nvarchar(100))

insert into @tab

select 1,'2011-1-1','1'

union

select 1,'2011-1-2','e'

union

select 1,'2011-1-3','e'

union

select 1,'2012-1-4','3'

union

select 1,'2012-1-5','4'

union

select 1,'2012-1-6','4'

select *,isnumeric(num) as isNum into #newTab from @tab

select *,ROW_NUMBER() over(partition by num order by dt) as numRowNum

into #numRowNumTab

from #newTab

update #numRowNumTab set num='"' where numRowNum>1 and isNum=0

select id,dt,num from #numRowNumTab

drop table #newTab

drop table #numRowNumTab


欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/bake/8009893.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-12
下一篇2023-04-12

发表评论

登录后才能评论

评论列表(0条)

    保存