Oracle with AS Usage

Source: Internet
Author: User

The WITH query statement is preceded with a, which is equivalent to building a temporary table before the query, the specified query results are stored with the temporary table, and can then be used more than once for further analysis and processing.


Grammar:

With _temptable as (SELECT * from table)

SELECT * FROM _temptable

Example:

With _tempstudent as (

SELECT * FROM T_student t where class = ' First Class 23 '

)

Select Sex,count (1) nums from _tempstudent where sex = ' man ' and Height > ' 170 '

UNION ALL

Select Sex,count (1) nums from _tempstudent where sex = ' female ' and height > ' 160 '


Multiple with as usage each temporary stock is directly separated by ","

with T1 as (

SELECT * from student where name in (' Zhang San ', ' John Doe ')

), T2 as (

SELECT * from student where name in (' Harry ')

)

SELECT * FROM t1

Union

SELECT * FROM T2


If the with as has nested conditions, multiple with AS, the back of the as interior can invoke the declared temporary object directly

with T1 as (

SELECT * from student where name in (' Zhang San ', ' John Doe ')

), T2 as (

SELECT * from t1 where name in (' Harry ')

)

SELECT * FROM T2


Oracle with AS Usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.