您的位置:首页 > 数据库

生僻sql

2016-05-12 00:00 274 查看
with 子句
提供定义临时关系的方法,这个定义只对包含with子句的查询有效。with子句是在SQL:1999中引入的,目前许多(但并非所有)数据库系统都提供支持

[code=plain]with student_temp(id,name,age) as(
select id,name,age from student where age > 20
)
select * from student_temp;

如上,建立了一个student_temp 的临时表,后者再根据student_temp来查询

case 结构
case语句可以用在任务应该出现值的地方

[code=plain]select id ,
case
when address is null then '未知'
else address
end
from student;

如上,在查询student表时,如果address为null.那么就用 '未知' 代替。

create table 扩展
当需要创建表参考现有的表,或将查询出来的数据保存到新表中

创建一张表参考现有的表

[code=plain]create table tmep_usr like s_user;

将查询出来的数据保存到新表中

[code=plain]create table temp_user as (
select * from s_user where dept = 1
)with data;

上面的语法在不同的数据库系统中的实现也不一样,要参考相应的手册。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: