SQL语句集锦
来源:互联网 发布:vmware14 上安装linux 编辑:程序博客网 时间:2024/06/03 08:48
1.对float类型进行精度截取
不四舍五入---》cast(字段1/字段2 as decimal(10,3))
四舍五入------》round(字段1/字段2,3)
2.将一个表中的数据插入到另一个表中
将一个表(表A)中的所有数据(有4个字段)插入到另一个表(表B)中的相应字段中,insert 语句因如何使用,两个表为:
表A:表名:results ,表中有四个字段:name,no,card,adno
表B: 表名:rs , 表中有8个字段:要将表A中的 name, no, card, adno 所有数据插入到表B中的name,no,card,bmmc
insert into rs (name,no,card,bmmc) select name,no,card,adno from esults
3.System.DBNull.Value与null的区别!
"null" means the object reference is invalid in .NET, when you retrieve a NULL value from the Database, it is a valid value to .NET, and it is represented by System.DBNull.Value
4.Union和order by的使用
union使用时会去掉 结果集中的重复数据;union all 则会全部显示,不管重复
在union中使用order by 可以
select * from(
select ....
union
select ...)
order by field
也可以使用列的在输出字段索引值
select ....
union
select ...
order by 4 --第四个字段
select articleid,title,classid,hits,imgNews
from (
select top 1 articleid,title,classid,hits,imgNews,dateandtime from article where ClassID=19 order by dateandtime desc--新闻
)t1
union
select articleid,title,classid,hits,imgNews
from (
select top 1 articleid,title,classid,hits,imgNews,dateandtime from article where ClassID=23 order by dateandtime desc--新品
)t2
union
select articleid,title,classid,hits,imgNews
from (
select top 1 articleid,title,classid,hits,imgNews,dateandtime from article where ClassID=96 order by dateandtime desc--军事
)t3
5.sql语句的执行时间
select语句前加:
declare @d datetime
set @d=getdate()
并在select语句后加:
select [语句执行花费时间(毫秒)]=datediff(ms,@d,getdate())
6.Oracle数据库
1. From子句:数据最少的表做放到最后面,
3个以上表时,交叉表为基础表.
2. Where子句:过滤最多数据的条件放到最后面,
表之间的连接语句放到最前面.
3. SELECT子句:避免使用 * .
4. 用Where子句替换HAVING子句
5. 在含有子查询的SQL语句中,
要特别注意减少对表的查询
6. 使用Exists的效率比In高,
表连接的方式比EXISTS更有效率
7. 避免在索引列上使用IS NULL和IS NOT NULL。
8. '<>'、'!='不再使用索引。
索引只能告知什么存在于表中,
而不能告知什么不存在于表中.
- SQL语句集锦!
- SQL语句集锦
- SQL语句集锦
- SQL语句集锦
- SQL语句集锦
- SQL语句集锦
- SQL语句集锦
- SQL语句集锦
- 经典SQL语句集锦
- 经典SQL语句集锦
- SQL语句集锦
- SQL语句集锦
- SQL语句集锦
- SQL语句集锦
- SQL语句集锦
- SQL语句集锦
- SQL语句集锦 zt
- SQL语句集锦
- 缓存技术
- 一次性读取数据的分页控件
- Hibernate之Configuration-SessionFactiory-Session
- 解决IIS的“Server Application Error”故障
- iphone gmail email push
- SQL语句集锦
- Event
- ExecuteScalar为空的两种情况
- 24. android dialog ——ProgressDialog 进度条对话框详解
- using 语句(C# 参考)
- 数字转换成字符串时保留小数位数
- ISP
- 在linux 下安装oralce
- ASP.NET2.0下含有DropDownList的GridView编辑、删除的完整例子