常用经典的SQL语句
2012-05-30 20:28
381 查看
1、写出一条sql语句:取出表a中第31到第40记录(sqlserver,以自动增长的id作为主键,注意:id可能不是连续的。
演变过程:1.select top 30 S_ID from StuInfo --先取出前30条数据
2.select *from StuInfo where S_ID not in (select top 30 S_ID from StuInfo) --取出S_ID不等于前30的
3.select top 10* from StuInfo where S_ID not in (select top 30 S_ID from StuInfo)--S_ID不再前30条的前10条数据
方法1:select top 10* from StuInfo where S_ID not in (select top 30 S_ID from StuInfo)
2、实现是1或0想显示为男或女
select name,Sex=
case Sex
when '1' then '男'
when '0' then '女'
end
from Tablename
3、嵌套子查询
select a,b,c from Table1 where a IN (select a from Table2)
4、编辑一个列
增加列:
alter table Table1 add username varchar(30) not null default ''
修改列:
alter table Table1 alter column username varchar(40)
删除列:
alter table Table1 drop column username
5、按范围查询编号在2到5之间的用户信息
select * from UserValue where UserID between 2 and 5
6、找出表ppp里面mum是最小的值的一条记录
方法1:select top 1 mum from ppp order by mum
方法2:select * from ppp where mum=(select Min(mum) from ppp)
7、复制表
select * into new from old where 1=0 (只复制表结构)
select * into new from old(拷贝数据)
8、在数据表A中,有一个字段LASTUPDATETIME,是最后更新的时间,如果要查最新更新的时间,如何写SQL语句
select * from A where LASTUPDATETIME=(select Max(LASTUPDATETIME)from A)
9、日期字符串转换函数to_char(),to_date()
select to_char(sysdate,'hh:mi:ss')from dual; 结果:10:51:43
select to_date('20080229132545','yyyy-mm-dd hh24:mi:ss')from dual 结果:2008-2-29 13:25:45
10、修改人员信息表(a01)的数据,将联系电话以11开头的人员的学历改为”大专”。
update Employee set E_XueLi ='大专' where E_Tel like'11%'
演变过程:1.select top 30 S_ID from StuInfo --先取出前30条数据
2.select *from StuInfo where S_ID not in (select top 30 S_ID from StuInfo) --取出S_ID不等于前30的
3.select top 10* from StuInfo where S_ID not in (select top 30 S_ID from StuInfo)--S_ID不再前30条的前10条数据
方法1:select top 10* from StuInfo where S_ID not in (select top 30 S_ID from StuInfo)
2、实现是1或0想显示为男或女
select name,Sex=
case Sex
when '1' then '男'
when '0' then '女'
end
from Tablename
3、嵌套子查询
select a,b,c from Table1 where a IN (select a from Table2)
4、编辑一个列
增加列:
alter table Table1 add username varchar(30) not null default ''
修改列:
alter table Table1 alter column username varchar(40)
删除列:
alter table Table1 drop column username
5、按范围查询编号在2到5之间的用户信息
select * from UserValue where UserID between 2 and 5
6、找出表ppp里面mum是最小的值的一条记录
方法1:select top 1 mum from ppp order by mum
方法2:select * from ppp where mum=(select Min(mum) from ppp)
7、复制表
select * into new from old where 1=0 (只复制表结构)
select * into new from old(拷贝数据)
8、在数据表A中,有一个字段LASTUPDATETIME,是最后更新的时间,如果要查最新更新的时间,如何写SQL语句
select * from A where LASTUPDATETIME=(select Max(LASTUPDATETIME)from A)
9、日期字符串转换函数to_char(),to_date()
select to_char(sysdate,'hh:mi:ss')from dual; 结果:10:51:43
select to_date('20080229132545','yyyy-mm-dd hh24:mi:ss')from dual 结果:2008-2-29 13:25:45
10、修改人员信息表(a01)的数据,将联系电话以11开头的人员的学历改为”大专”。
update Employee set E_XueLi ='大专' where E_Tel like'11%'
相关文章推荐
- 我常用经典SQL语句[就先写一句吧]
- 常用经典SQL语句
- 50个经典常用的sql语句
- oracle中常用经典sql查询语句。
- sql一些常用的经典语句,最后是select as的用法
- 经典MySQL语句大全和常用SQL语句命令的作用。
- 经典MSSQL语句大全和常用SQL语句命令的作用
- 总结经典常用的SQL语句(2)
- SQL常用经典语句
- 经典MSSQL语句大全和常用SQL语句命令的作用
- 常用经典SQL语句大全完整版
- 经典SQL语句大全以及50个常用的sql语句
- 总结经典常用的SQL语句(2)
- 常用经典SQL语句大全完整版--详解+实例 《来自网络,很全没整理,寄存与此》
- 收集一些工作中常用的经典SQL语句
- sql经典常用语句
- 常用经典SQL语句
- OracleSQL常用(以及经典)语句
- 常用经典SQL语句(收藏)
- 经典SQL语句大全、50个常用的sql语句