Рассмотрим таблицу CUSTOMERS, имеющую следующие записи:
SQL> SELECT * FROM CUSTOMERS;
+----+----------+-----+-----------+----------+ | ID | NAME | AGE | ADDRESS | SALARY | +----+----------+-----+-----------+----------+ | 1 | Maxim | 35 | Moscow | 21000.00 | | 2 | AndreyEx | 38 | Krasnodar | 55500.00 | | 3 | Oleg | 33 | Rostov | 34000.00 | | 4 | Masha | 35 | Moscow | 31500.00 | | 5 | Ruslan | 34 | Omsk | 43000.00 | | 6 | Dima | 32 | SP | 45000.00 | | 7 | Roma | 34 | SP | 10000.00 | +----+----------+-----+-----------+----------+ 7 rows in set (0.00 sec)
Вот некоторые простые примеры, демонстрирующие использование операторов сравнения в SQL:
SQL> SELECT * FROM CUSTOMERS WHERE SALARY > 45000;
+----+----------+-----+-----------+----------+ | ID | NAME | AGE | ADDRESS | SALARY | +----+----------+-----+-----------+----------+ | 2 | AndreyEx | 38 | Krasnodar | 55500.00 | +----+----------+-----+-----------+----------+ 1 rows in set (0.00 sec)
SQL> SELECT * FROM CUSTOMERS WHERE SALARY = 55000;
+----+----------+-----+-----------+----------+ | ID | NAME | AGE | ADDRESS | SALARY | +----+----------+-----+-----------+----------+ | 2 | AndreyEx | 38 | Krasnodar | 55500.00 | +----+----------+-----+-----------+----------+ 1 rows in set (0.00 sec)
SQL> SELECT * FROM CUSTOMERS WHERE SALARY != 55000;
+----+----------+-----+-----------+----------+ | ID | NAME | AGE | ADDRESS | SALARY | +----+----------+-----+-----------+----------+ | 1 | Maxim | 35 | Moscow | 21000.00 | | 3 | Oleg | 33 | Rostov | 34000.00 | | 4 | Masha | 35 | Moscow | 31500.00 | | 5 | Ruslan | 34 | Omsk | 43000.00 | | 6 | Dima | 32 | SP | 45000.00 | | 7 | Roma | 34 | SP | 10000.00 | +----+----------+-----+-----------+----------+ 6 rows in set (0.00 sec)
SQL> SELECT * FROM CUSTOMERS WHERE SALARY <> 55000;
+----+----------+-----+-----------+----------+ | ID | NAME | AGE | ADDRESS | SALARY | +----+----------+-----+-----------+----------+ | 1 | Maxim | 35 | Moscow | 21000.00 | | 3 | Oleg | 33 | Rostov | 34000.00 | | 4 | Masha | 35 | Moscow | 31500.00 | | 5 | Ruslan | 34 | Omsk | 43000.00 | | 6 | Dima | 32 | SP | 45000.00 | | 7 | Roma | 34 | SP | 10000.00 | +----+----------+-----+-----------+----------+ 6 rows in set (0.00 sec)
SQL> SELECT * FROM CUSTOMERS WHERE SALARY >= 4500;
+----+----------+-----+-----------+----------+ | ID | NAME | AGE | ADDRESS | SALARY | +----+----------+-----+-----------+----------+ | 2 | AndreyEx | 38 | Krasnodar | 55500.00 | | 6 | Dima | 32 | SP | 45000.00 | +----+----------+-----+-----------+----------+ 2 rows in set (0.00 sec)