(Contents)(Previous)(Next)

Arithmetic in a Condition

Column names can also be used within conditional expressions.

SELECT hno, roomtype, price

FROM room

WHERE price*7 < 500

AND roomtype = 'single'

The query only selects hotels where the weekly price of a single room is less than $ 500.00. The weekly price is not displayed, because this was not required in the output list.

Find all hotels where the weekly price is less than $ 500.00 after a price increase of 5 percent:

SELECT hno, roomtype, price

FROM room

WHERE (price*1.05)*7 < 500

AND roomtype = 'single'

The price for two days can be calculated in the following way:

SELECT hno, roomtype, price*2 two_days

FROM room

WHERE roomtype = 'single'

or

SELECT hno, roomtype, price+price two_days

FROM room

WHERE roomtype = 'single'

Show the prices for one day, two days and a week:

SELECT hno, roomtype, price, price+price two_days, price*7 week

FROM room

WHERE roomtype = 'single'

Show the customers with positive accounts and add the constant 'CREDIT_BALANCE':

SELECT name, account, 'CREDIT_BALANCE' comment

FROM customer

WHERE account > 0

Let the sum of the positive accounts be $ 9774.00. Show the percentage portions of all customers (with positive accounts), rounded to the second place to the right of the decimal point, and sorted in descending order:

SELECT name, account, fixed (account/9774.00*100,5,2) percentage

FROM customer

WHERE account > 0

ORDER BY 3 DESC


(Contents)(Previous)(Next)