SQL-With函数使用
WITH AS短语,也叫做子查询部分,定义一个SQL片断后,该SQL片断可以被整个SQL语句所用到。有的时候,with as是为了提高SQL语句的可读性,减少嵌套冗余。
在标准的数据库中,如hive,Oracle,DB2,SQL SERVER,PostgreSQL都是支持WITH AS 语句进行递归查询。只有MySQL是不支持的
--单个
with A as (select * from student)
select * from A
--多个
with A as (select distinct(sno),sname,ssex,sclass from student),
B as (select sno,cno,degree from score )
select * from A,B
where A.sno =B.sno

浙公网安备 33010602011771号