摘要: select column1,avg(column2) from table_name group by column1 having avg(column2) ***说明: 1、group by:以column1为一组计算column2的平均值必须和avg、sum等整合性查询的关键字一起使用。 2、having:必须和group by一起使用作为整合性的限制。 阅读全文
posted @ 2011-01-03 17:29 yangzhiqw 阅读(264) 评论(0) 推荐(0) 编辑
摘要: declare @aa int set @aa = 1update EWC_HT_Contract set ContractCode = a.ContractCode + cast (@aa as nvarchar(10)),@aa = @aa +1 from ( select ContractCode from Contractwhere MasterID = 1) as awhere MasterID = 2 阅读全文
posted @ 2011-01-03 17:27 yangzhiqw 阅读(162) 评论(0) 推荐(0) 编辑
摘要: declare @tbname varchar(250) declare #tb cursor for select name from sysobjects where objectproperty(id,'IsUserTable')=1 open #tb fetch next from #tb into @tbname while @@fetch_status=0 begin exec('alter table ['+@tbname+'] nocheck constraint all') -- nocheck关闭所有约束 check开启所有约束 fetch next from #tb 阅读全文
posted @ 2011-01-03 00:17 yangzhiqw 阅读(865) 评论(0) 推荐(0) 编辑
摘要: 我们要做到不但会写SQL,还要做到写出性能优良的SQL,以下为笔者学习、摘录、并汇总部分资料与大家分享! 1、选择最有效率的表名顺序(只在基于规则的优化器中有效): ORACLE 的解析器按照从右到左的顺序处理FROM子句中的表名,FROM子句中写在最后的表(基础表 driving table)将被最先处理,在FROM子句中包含多个表的情况下,你必须选择记录条数最少的表作为基础表。如果有3个以上的表连接查询, 那就需要选择交叉表(intersection table)作为基础表, 交叉表是指那个被其他表所引用的表. 2、WHERE子句中的连接顺序: ORACLE采用自下而上的顺序解析WHERE 阅读全文
posted @ 2011-01-03 00:15 yangzhiqw 阅读(137) 评论(0) 推荐(0) 编辑