一些初级面试题

 

1.把所有姓李的人都改成姓张的.

update xingming set name=''+substring(name,2,len(name)-1) where left(name,1)='' 
或者
update xingming set name=''+substring(name,2,len(name)-1) where charindex('李',name)=1

注意不要写成这样:

update xingming set name=replace(name,'','')

如果有人叫'李小李',则会被无情地改为'张小张'.


 2.

     

把这两个表的数据用以这种方式现实:

select dname,b.yj 一月份,c.yj 二月份,d.yj 三月份 from 
dept a left join yj b 
on a.dep=b.dep and b.mon='一月份' left join 
yj c on a.dep = c.dep and c.mon='二月份' left join yj d
 on a.dep = d.dep and d.mon='三月份'

3.

   查询显示结果为:

select a.year,a.m1,b.m2,c.m3,d.m4 from
(select year,amount m1 from nx where month=1) a,
(select year,amount m2 from nx where month=2) b,
(select year,amount m3 from nx where month=3) c,
(select year,amount m4 from nx where month=4) d
where a.year=b.year and a.year=c.year and a.year=d.year

 

看查询结果分析语句应怎么写,不要在意显示结果的列名.列名可以是别名.

带Null值的,一定是有左外连接或者右外链接的.而且不用group by 因为不断拿左表当比对,右表不会多于左表,所以不会重复.

count(yilie)  和count同时被查询的列一定要在聚合函数中的.


replace可以嵌套. replace(列,要被替换内容,被替换成的内容)

一般大家都会写成这样:select * from Production.Document where DocumentSummary like'%bicycle%'了解这个函数以后,大家可以这样写:select * from Production.Document where charindex('bicycle',DocumentSummary)>0 这种方法比like'%%'的形式速度上要快很多.

转载于:https://www.cnblogs.com/xiaodaidu/archive/2013/04/04/2999765.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值