If this is the wrong place to post this, please let me know and I will move it.
I am trying to take a query from a report writer and move it to our software package and I am having a little difficulty deciphering the sql statement that was built by impromptu.
select "c26" "c1" , "c25" "c2" , "c17" "c3" , "c24" "c4" ,
"c18" "c5" ,"c23" "c6" , "c22" "c7" , "c21" "c8" ,
"c20" "c9" , "c19" "c10" , "c16" "c11"
from (select T1."order_id" "c14" , T1."customer_id" "c15" , sum(T1."amount") "c16" from "open_item" T1
group by T1."customer_id", T1."order_id"
having sum(T1."amount") < 0) D3,
(select T1."order_id" "c17" , T1."customer_id" "c18" ,
T1."source" "c19" , T1."ship_date" "c20" , T1."reference_number" "c21" , T1."record_type" "c22" ,
T1."gl_date" "c23" , T1."bill_date" "c24" ,
T1."amount" "c25" , T1."company_id" "c26"
from "open_item" T1) D2
where ("c18" = "c15" or "c18" is null and "c15" is null)
and ("c17" = "c14" or "c17" is null and "c14" is null)
order by 5 asc , 3 asc , 4 asc
I am not new to sql, but pretty new to more then just the average select statement. From what I can figure out is that the first select statement is running off the resutls of the next select, but I am not sure how the 3rd select statement fits into this. I have tried to find information on multiple subqueries, but not getting very far.
My guess is that it is similar to saying this:
select * from (1st_query, 2nd_query) OR
select * from (table, table)
Is that correct?
Is the where statement at the very end of this for the 1st select statement or the 3rd?
Any help figuring this out is greatly appriciated.
chris
I am trying to take a query from a report writer and move it to our software package and I am having a little difficulty deciphering the sql statement that was built by impromptu.
select "c26" "c1" , "c25" "c2" , "c17" "c3" , "c24" "c4" ,
"c18" "c5" ,"c23" "c6" , "c22" "c7" , "c21" "c8" ,
"c20" "c9" , "c19" "c10" , "c16" "c11"
from (select T1."order_id" "c14" , T1."customer_id" "c15" , sum(T1."amount") "c16" from "open_item" T1
group by T1."customer_id", T1."order_id"
having sum(T1."amount") < 0) D3,
(select T1."order_id" "c17" , T1."customer_id" "c18" ,
T1."source" "c19" , T1."ship_date" "c20" , T1."reference_number" "c21" , T1."record_type" "c22" ,
T1."gl_date" "c23" , T1."bill_date" "c24" ,
T1."amount" "c25" , T1."company_id" "c26"
from "open_item" T1) D2
where ("c18" = "c15" or "c18" is null and "c15" is null)
and ("c17" = "c14" or "c17" is null and "c14" is null)
order by 5 asc , 3 asc , 4 asc
I am not new to sql, but pretty new to more then just the average select statement. From what I can figure out is that the first select statement is running off the resutls of the next select, but I am not sure how the 3rd select statement fits into this. I have tried to find information on multiple subqueries, but not getting very far.
My guess is that it is similar to saying this:
select * from (1st_query, 2nd_query) OR
select * from (table, table)
Is that correct?
Is the where statement at the very end of this for the 1st select statement or the 3rd?
Any help figuring this out is greatly appriciated.
chris