Entering content frame

This graphic is explained in the accompanying text Arithmetic Operations Locate the document in the library structure

You can use expressions that have arithmetic operations (such as + for additions and - for subtractions).

Prerequisites

You require the demo data for the SQL Tutorial.

Start the query tool SQL Studio as database administrator MONA with password RED and log on to the demo database instance DEMODB.

Arithmetic in the Results Table

You can use a data query both to determine data that already exists in a table and calculate values on the basis of this data.

 

SELECT hno, price*7 weekly_price, type
  FROM hotel.room
    WHERE type = 'single' AND hno <50

Displaying the weekly price for a single room; the display has been restricted to those hotels with a hotel number below 50

Result

HNO

WEEKLY_PRICE

TYPE

10

945

Single

20

490

Single

30

315

Single

40

595

Single

 

Arithmetic in Search Conditions

In search conditions, you can also use expressions that have arithmetic operations.

 

SELECT hno, type, price
  FROM hotel.room
    WHERE price*7 < 500 AND type = 'single'

Displaying the hotels whose weekly price for a single room is below 500.00 euro

Result

HNO

TYPE

PRICE

20

Single

70

30

Single

45

100

Single

60

110

Single

70

 

SELECT hno, type, price
  FROM hotel.room
    WHERE (price*1.05)*7 < 500 AND type = 'single'

Displaying the hotels whose weekly price for a single room is below 500.00 euro, even after a price increase of 5 percent

Result

HNO

TYPE

PRICE

30

Single

45

100

Single

60

 

See also:

SQL Reference Manual, Structure linkExpression (expression)

More examples for Data Query

 

Leaving content frame