jake.keh

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

2013年4月7日

摘要: 在列的筛选中,不要对列进行处理,否则用不到列的索引。 阅读全文
posted @ 2013-04-07 13:52 jake.keh 阅读(102) 评论(0) 推荐(0)

摘要: like 'D%' D开头like '_e%' 第二个字母是elike '[ABC]%' A或者B或者C开头like '[A-E]%' A-E开头like '[^A-E]%' 非A-E开头 阅读全文
posted @ 2013-04-07 13:25 jake.keh 阅读(123) 评论(0) 推荐(0)

摘要: select substring(str,start,length);sql的第一位置可以是0,也可以是1,如果start+length大于了str的length,则返回从头开始,整个strstuff(str,start,del_len,rep_str)select stuff('abc',2,1,'xyz');==>axyzc 阅读全文
posted @ 2013-04-07 13:20 jake.keh 阅读(365) 评论(0) 推荐(0)

摘要: over支持所有的聚合函数和排名函数不需要group by,可以直接显示基础行的数据,并且在同一行可以显示聚合函数的运算结果select salesorderid,orderdate,subtotal,sum(subtotal) over() from [Sales].salesorderheader如果需要对结果进行分组,可以在over内使用partition byselect salesorderid,orderdate,subtotal,customerid,sum(subtotal) over(partition by customerid) from [Sales].salesord 阅读全文
posted @ 2013-04-07 11:24 jake.keh 阅读(130) 评论(0) 推荐(0)

摘要: select top 10 * from workersselect top 10 percent from workers如果在percent中出现小数,会向上去整 阅读全文
posted @ 2013-04-07 10:50 jake.keh 阅读(109) 评论(0) 推荐(0)

摘要: select name,salary from workersorder by hiredate在select子句中没有出现的列,也是可以在order by中使用的select distinct name,countryfrom workersorder by hiredate在此句中order by使用的列没有意义,只能使用distinct中的列 阅读全文
posted @ 2013-04-07 10:45 jake.keh 阅读(124) 评论(0) 推荐(0)

摘要: countsumminmaxavg注:1.不会忽略null值,count(*)2.by 列计算会忽略空值,count(qty)3.求值的行不包含重复行,count(distinct qty) 阅读全文
posted @ 2013-04-07 10:25 jake.keh 阅读(89) 评论(0) 推荐(0)

摘要: fromwheregroup byhavingselectorder by注:这就是在group by和having子句中不能使用别名而在order by中可以使用别名的原因 阅读全文
posted @ 2013-04-07 10:22 jake.keh 阅读(159) 评论(0) 推荐(0)