Background documentationArithmetic Operations Locate this document in the navigation structure

 

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

Prerequisites

You can use the demo data for the SQL tutorial. Start the Database Studio as database administrator MONA with the password RED and log on to demo database DEMODB: Logging On to a Database.

Activities

You can use Database Studio to enter and execute SQL statements. More information: Working with SQL Statements: Overview

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

More Information

SQL Reference Manual, Expression (expression)

More examples for Data Query