汇总:常用 SQL 语句大全(2)
来源:互联网 发布:js代码美化插件 编辑:程序博客网 时间:2024/05/22 14:42
以下是引用片段:
use pangu
update employee
set e_wage =
case
when job_level = ’1’ then e_wage*1.08
when job_level = ’2’ then e_wage*1.07
when job_level = ’3’ then e_wage*1.06
else e_wage*1.05
end
--WHILE CONTINUE BREAK
以下是引用片段:
declare @x int @y int @c int
select @x = 1 @y=1
while @x < 3
begin
print @x --打印变量x 的值
while @y < 3
begin
select @c = 100*@x + @y
print @c --打印变量c 的值
select @y = @y + 1
end
select @x = @x + 1
select @y = 1
end
--WAITFOR
--例 等待1 小时2 分零3 秒后才执行SELECT 语句
以下是引用片段:
waitfor delay ’01:02:03’
select * from employee
--例 等到晚上11 点零8 分后才执行SELECT 语句
以下是引用片段:
waitfor time ’23:08:00’
select * from employee
***SELECT***
以下是引用片段:
select *(列名) from table_name(表名) where column_name operator value
ex:(宿主)
select * from stock_information where stockid = str(nid)
stockname = 'str_name'
stockname like '% find this %'
stockname like '[a-zA-Z]%' --------- ([]指定值的范围)
stockname like '[^F-M]%' --------- (^排除指定范围)
--------- 只能在使用like关键字的where子句中使用通配符)
or stockpath = 'stock_path'
or stocknumber < 1000
and stockindex = 24
not stock*** = 'man'
stocknumber between 20 and 100
stocknumber in(10,20,30)
order by stockid desc(asc) --------- 排序,desc-降序,asc-升序
order by 1,2 --------- by列号
stockname = (select stockname from stock_information where stockid = 4)
--------- 子查询
--------- 除非能确保内层select只返回一个行的值,
--------- 否则应在外层where子句中用一个in限定符
以下是引用片段:
select distinct column_name form table_name --------- distinct指定检索独有的列值,不重复
select stocknumber ,stocknumber + 10 = stocknumber + 10 from table_name
select stockname , stocknumber = count(*) from table_name group by stockname
--------- group by 将表按行分组,指定列中有相同的值
以下是引用片段:
having count(*) = 2 --------- having选定指定的组
select *
from table1, table2
where table1.id *= table2.id -------- 左外部连接,table1中有的而table2中没有得以null表示
table1.id =* table2.id -------- 右外部连接
select stockname from table1
union [all] ----- union合并查询结果集,all-保留重复行
select stockname from table2
***insert***
以下是引用片段:
insert into table_name (Stock_name,Stock_number) value (xxx,xxxx)
value (select Stockname , Stocknumber from Stock_table2)---value为select语句
***update***
以下是引用片段:
update table_name set Stockname = xxx [where Stockid = 3]
Stockname = default
Stockname = null
Stocknumber = Stockname + 4
***delete***
以下是引用片段:
delete from table_name where Stockid = 3
truncate table_name ----------- 删除表中所有行,仍保持表的完整性
drop table table_name --------------- 完全删除表
- 汇总:常用 SQL 语句大全(2)
- 汇总:常用 SQL 语句大全(1)
- 汇总:常用 SQL 语句大全(3)
- 汇总:常用 SQL 语句大全(4)
- 常用SQL语句汇总
- 常用SQL语句汇总
- SQL常用语句汇总
- 常用SQL语句汇总
- 常用SQL语句汇总
- 常用SQL 语句汇总
- 常用SQL语句汇总
- 常用sql语句汇总
- 常用 sql 语句汇总
- SQL常用语句大全
- 常用 SQL 语句大全
- sql常用语句大全
- 常用 SQL 语句大全
- 常用 SQL 语句大全
- 谈函数指针(全局/类成员函数)和函数对象
- 进程调度方式
- 【转】opencv 配置
- 【转】关于DLL的一点介绍
- 汇总:常用 SQL 语句大全(1)
- 汇总:常用 SQL 语句大全(2)
- 网上邻居
- 汇总:常用 SQL 语句大全(3)
- 汇总:常用 SQL 语句大全(4)
- 在SQL Server下数据库链接的使用
- 轻松掌握用SQL来合并查询
- 浅谈SQL Server数据类型最大值
- 用SQL建立索引
- 轻松掌握SQL Server数据同步技术