生僻sql

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

with student_temp(id,name,age) as(
	select id,name,age from student where age > 20
)
select * from student_temp;

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

case 结构
    case语句能够用在任务应该出现值的地方it

select id ,
      case 
	     when address is null then '未知' 
		 else address 
      end 
from student;

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

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

建立一张表参考现有的表select

create table tmep_usr like s_user;

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

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

上面的语法在不一样的数据库系统中的实现也不同,要参考相应的手册。方法

相关文章
相关标签/搜索