首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

sql 基础 1

2012-12-26 
sql 基础 一1、and 的优先级 高于 or2、asselect sal as salary, comm as commissionfrom emp3、连接字符串Or

sql 基础 一

1、and 的优先级 高于 or2、asselect sal as salary, comm as commission   from emp3、连接字符串    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 <= 57、is null / is not null8、将 null 翻译成其他     可以使用 case when 语句     select coalesce(null_column,'is null') from table_name;     select coalesce(create_user , 'system') from emp;        

热点排行