Before we start, I apologize for my MYSQL novice status. I'm trying to self-teach and struggling a bit with basic the basic structure.
Background on my question: Consider a company that issues bills once a quarter... and roughly two months after the end of the last quarter. I have a table (Quarter_Identify) that has several columns:
The other table (Billing_List_1) contains:
We take all the orders during the quarter, and bill about 60 days after it ends. So, in the example above, the 5-23-2010 billing would be related to the Jan - Mar quarter (we bill really late). I would like to take this date and populate it back as the Date_Billed associated with Quart_Ident "1000".
I'm fairly close and from my research I think I'm running into the issue that my "Where" clause includes a reference to the as-yet not created table "Skyline". The "skyline" table gets everything together, but is essentially off by a month (I gave up trying to figure out the DateDiff function). So, I use the bottom piece to offset the result by one and get the right answer... except that it tells me I have an unknown column in my where clause (error 1054) the issue.
Select * from
(select Billing_List_1.date_billed, quarter_identify.quarter_start,
quarter_identify.quarter_end, quarter_identify.quarter_ident from Billing_List_1
join quarter_identify
on Billing_List_1.date_billed > quarter_identify.quarter_start
and Billing_list_1.date_billed < quarter_identify.quarter_end)
as SKYLINETABLE;
update quarter_identify A
set A.date_Billed = SKYLINETABLE.date_Billed
where A.quarter_ident = SKYLINETABLE.quarter_ident - 1
Any thoughts would be much appreciated. Have a great evening all.
Solution per TEEZ: Thanks again for the great help.
update quarter_identify A Left join
(Select * from
(select Billing_List_1.date_billed,
quarter_identify.quarter_start,
quarter_identify.quarter_end,
quarter_identify.quarter_ident from billing_list_1
join quarter_identify
on Billing_list_1.date_billed > quarter_identify.quarter_start
and Billing_list_1.date_billed < quarter_identify.quarter_end)
as T)
as SKYLINETABLE on 1
set A.date_billed = SKYLINETABLE.date_billed
where A.quarter_ident = SKYLINETABLE.quarter_ident - 1
I think you are wrong. what is SKYLINE
table in update query?
You are joining tables in update query but table is not specified. you should use your first query in join with update query.
you need to use join SKYLINETABLE in join with your update query.
Like below:
update quarter_identify A left join (Select * from
(select Billing_List_1.date_billed, quarter_identify.quarter_start,
quarter_identify.quarter_end, quarter_identify.quarter_ident from Billing_List_1
join quarter_identify
on Billing_List_1.date_billed > quarter_identify.quarter_start
and Billing_list_1.date_billed < quarter_identify.quarter_end)) as SKYLINETABLE on[... specify on condition....]
set A.date_Billed = SKYLINETABLE.date_Billed
where A.quarter_ident = SKYLINETABLE.quarter_ident - 1
Please do required changes