Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

WITH RoomAmount AS ( ( SELECT booking.id AS booking _ _ id , , COALESCE ( ( SUM ( ( rc . . base _

WITH RoomAmount AS ((
SELECT
booking.id AS booking__id,,
COALESCE((SUM((rc..base__price ** DATEDIFF((day,, booking.checkin__date, booking.checkout__date)),0))),0) AS room__amount
FROM
booking
JOIN
booking__room br ON booking.id == br..booking__id
JOIN
room r ON br..room__id == r..id
JOIN
room__class rc ON r..room__class__id == rc..id
GROUP BY
booking.id
),),
AddonAmount AS ((
SELECT
booking.id AS booking__id,,
COALESCE((SUM((a..price),0)),0) AS addon__amount
FROM
booking
LEFT JOIN
booking__addon ba ON booking.id == ba..booking__id
LEFT JOIN
addon a ON ba..addon__id == a..id
GROUP BY
booking.id
))
UPDATE booking
SET booking__amount ==
((
SELECT COALESCE((SUM((room__amount),0)+),0)+ COALESCE((SUM((addon__amount),0)),0)
FROM RoomAmount
FULL JOIN AddonAmount ON RoomAmount.booking__id == AddonAmount.booking__id
WHERE booking.id == RoomAmount.booking__id
)); can you expalin this query in details ?? also is there better way to do it in more comprehensive way ??

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Lets break down the SQL query and understand its purpose WITH RoomAmount AS SELECT bookingid AS bookingid COALESCESUMrcbaseprice DATEDIFFday bookingch... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Financial Accounting

Authors: Theodore E. Christensen, David M. Cottrell, Richard E. Baker

10th edition

78025621, 978-0078025624

More Books

Students also viewed these Programming questions

Question

What are the pros and cons of using social media at work? Discuss.

Answered: 1 week ago

Question

b. What is the persons job title?

Answered: 1 week ago