CTE Chain
Medium
1
66.7% Acceptance
Create a chain of three Common Table Expressions (CTEs) to perform successive transformations on the invoice data.
Table to be used: Invoice
Instructions:
- Use the
Invoice
table from the Chinook database. - Create a sequence of three CTEs.
- The first CTE (
CTE1
) should take theTotal
column from theInvoice
table and multiply it by 1.1, naming this new columnTransformedTotal1
. - The second CTE (
CTE2
) should take theTransformedTotal1
column fromCTE1
and multiply it by 0.9, naming this new columnTransformedTotal2
. - The third CTE (
CTE3
) should take theTransformedTotal2
column fromCTE2
and multiply it by 1.05, naming this new columnTransformedTotal
. - The final output should have the columns:
InvoiceId
: Represents the ID of the invoice.TransformedTotal
: The final transformed total after all the operations performed in the CTEs.
- The results should be ordered by the
InvoiceId
in ascending order.
Expected Columns in Final Output:
InvoiceId
TransformedTotal
Order By: InvoiceId