What I'm trying to do is take a guests duration of stay and multiplying it by their room rate, adding an invoice (for any purchases they may have made at the resort) and adding a dining bill to give them a total cost of their stay by guest name.
I have the following query:
SELECT gr.g_name, (DATEDIFF(d, r.res_checkout_date, r.res_checkin_date) * pp.rate ) + ISNULL(i.inv_amount, 0) + ISNULL(d.total_dining, 0)
FROM guest_reservation gr
LEFT OUTER JOIN invoice i ON gr.confirm_no = i.confirm_no
JOIN reservation r ON gr.confirm_no = r.confi开发者_JS百科rm_no
JOIN price_plan pp ON r.price_plan = pp.price_plan;
LEFT OUTER JOIN (SELECT r_confirmation_no, SUM(price) as total_dining
FROM dining_order do JOIN dining_menu dm ON do.item = dm.item
GROUP BY r_confirmation_no, price) as d ON d.r_confirmation_no = r.confirm_no
When I run that query however I get the following error messages:
"Msg 156, Level 15, State 1, Line 6 Incorrect syntax near the keyword 'LEFT'. Msg 156, Level 15, State 1, Line 8 Incorrect syntax near the keyword 'as'."
Any ideas?
The above query uses the following tables:
The guest reservation table has the following columns with data:
- confirm_no
- agent_id
- g_name
- g_phone
The reservation table has the following columns with data:
- confirm_no
- credit_card_no
- res_checkin_date
- res_checkout_date
- default_villa_type
- price_plan
The invoice table has the following columns with data:
- inv_no
- inv_date
- inv_amount
- confirm_no
The price plan table has the following columns with data:
- price_plan
- rate
- default_villa_type
- bed_type
The syntax error is because of the ;
in pp.price_plan;
.
精彩评论