sql - First query data is used in second query -


i have query get_product:

select a.product_id, a.name, a.description, a.type_id, b.series_name product_data inner join series b on a.series_raw_id = b.series_raw_id  a.product_id = 503061 , a.registration_type_id = 4 order b.series_name  

and second query

select b.series_name, a.tempacc_status   access_fact inner join  **get_product** b on a.tempacc_product_id = b.product_id a.tempacc_date_id between 6717 , 6808  , a.reason_id_total = 0 group series_name,  status 

in second query use data first query (get_product first query). how table here?

you use with clause.

for example,

with get_product   (select a.product_id,     a.name,     a.description,     a.type_id,     b.series_name product_data   inner join series b   on a.series_raw_id         = b.series_raw_id   a.product_id         = 503061   , a.registration_type_id = 4   order b.series_name   ) select b.series_name,   a.tempacc_status access_fact inner join get_product b on a.tempacc_product_id = b.product_id a.tempacc_date_id between 6717 , 6808 , a.reason_id_total = 0 group series_name,   status; 

or, use inline view

select b.series_name,   a.tempacc_status access_fact inner join   (select a.product_id,     a.name,     a.description,     a.type_id,     b.series_name product_data   inner join series b   on a.series_raw_id         = b.series_raw_id   a.product_id         = 503061   , a.registration_type_id = 4   order b.series_name   ) b on a.tempacc_product_id = b.product_id a.tempacc_date_id between 6717 , 6808 , a.reason_id_total = 0 group series_name,   status; 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -