SQL扫盲贴(持续更新)

1)select top 1 查询数据库中 排在第一行的数据
select top 1 * from table order by 成绩
union
select top 1 * from talbe where id not in(select top 2 id from table order by 成绩)

结果是第一名和第三名的数据

2)
如下代码,怎样写成一句,或中间用什么字符隔开才能同时运行

update Yao_Article set Author='/1/35/' where Author='山东 - 历下'
update Yao_Article set Author='/1/36/' where Author='山东 - 市中'
update Yao_Article set Author='/1/37/' where Author='山东 - 槐荫'
update Yao_Article set Author='/1/38/' where Author='山东 - 天桥'
update Yao_Article set Author='/1/39/' where Author='山东 - 历城'
update Yao_Article set Author='/1/40/' where Author='山东 - 长清'
update Yao_Article set Author='/1/41/' where Author='山东 - 平阴'
update Yao_Article set Author='/1/42/' where Author='山东 - 济阳'

update Yao_Article set Author=(case when Author='山东 - 历下'  then '/1/35/' when Author='山东 - 市中' then '/1/36/' ...... when Author='山东 - 济阳' then '/1/42/' else Author end) where Author like '山东 - %'


其他例子如:根据不同条件选择

select 姓名,工龄,
(case when (工龄>= '35') then '90%'
when (工龄>='30' and 工龄<'35') then '85%'
when (工龄>='20' and 工龄<'30') then '80%'
when (工龄>='10' and 工龄<'20') then '70%'
else 0 end) as '计算比例'
from 表
ps:else 后面不能再跟 then
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值