sql 基础 一

[color=blue]请关注新浪微博 账号:大数据进行时([url]http://weibo.com/u/3272022684[/url])[/color]



1、
and 的优先级 高于 or

2、as
select sal as salary, comm as commission
from emp

3、连接字符串
Oracle/DB2/PostgreSQL:
select ename||' WORKS AS A '||job as msg from emp where deptno=10;

mysql
select concat(ename,'WORKS AS A',job) as msg from emp where deptno=10;

SqlServer
select ename + ' WORKS AS A ' + job as msg from emp where deptno=10;

4、case - when
select ename,sal,
case when sal <= 2000 then 'UNDERPAID'
when sal >= 4000 then 'OVERPAID'
else 'OK'
end as salary
from emp;

5、查询条数(分页查询)
DB2
select * from emp fetch first 5 rows only;

MySql
select * from table_name limit x , y;
select * from emp limit 5;

Oracle
select * from table_name where rownum >= x and rownum <= y;(rownum 从 1 开始)
select * from emp where rownum <= 5

SqlServer
select top 5 * from emp;

6、随机获取记录
DB2
select ename,job from emp order by rand() fetch first 5 rows only;

MySql
select * from table_name order by rand() limit x , y;
select * from emp order by rand() limit 5;

Oracle
select * from (
select * from table_name order by dbms_random.value()
)where rownum <= 5

7、is null / is not null

8、将 null 翻译成其他
可以使用 case when 语句
select coalesce(null_column,'is null') from table_name;
select coalesce(create_user , 'system') from emp;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值