mal1kov
@mal1kov
Притворись дураком 5 минут, чем быть им всю жизнь.

SQL, несколько условий при выборке, как правильно сделать?

Я должен вывести товары из таблиц, в котором 1 и 3 соединяются с join и у которых speed>750
Но speed в PC показывает правильно по условии а Laptop нет.
select t2.type, t2.maker, t1.speed, t3.speed, t1.price, t3.price
from pc t1
full join product t2 on t1.model=t2.model
full join laptop t3 on t2.model = t3.model
where type='Laptop' or type='PC' and t1.speed>750 or t3.speed>750
group by t2.type, t2.maker, t1.speed, t3.speed, t1.price, t3.price

Структура PC:
Таблица "public.pc"
 Столбец |          Тип          | Правило сортировки | Допустимость NULL |           По умолчанию
---------+-----------------------+--------------------+-------------------+----------------------------------
 code    | integer               |                    | not null          | nextval('pc_code_seq'::regclass)
 model   | character varying(50) |                    | not null          |
 speed   | smallint              |                    | not null          |
 ram     | smallint              |                    | not null          |
 hd      | real                  |                    | not null          |
 cd      | character varying(10) |                    | not null          |
 price   | numeric(12,2)         |                    |                   |
 type    | integer               |                    | not null          | 1
Индексы:
    "pc_pkey" PRIMARY KEY, btree (code)

Laptop:
Таблица "public.laptop"
 Столбец |          Тип          | Правило сортировки | Допустимость NULL |             По умолчанию
---------+-----------------------+--------------------+-------------------+--------------------------------------
 code    | integer               |                    | not null          | nextval('laptop_code_seq'::regclass)
 model   | character varying(50) |                    | not null          |
 speed   | smallint              |                    | not null          |
 ram     | smallint              |                    | not null          |
 hd      | real                  |                    | not null          |
 cd      | character varying(10) |                    | not null          |
 price   | numeric(12,2)         |                    |                   |
 screen  | character varying(5)  |                    |                   |
 type    | integer               |                    | not null          | 1
Индексы:
    "laptop_pkey" PRIMARY KEY, btree (code)

Product:
Таблица "public.product"
 Столбец |          Тип          | Правило сортировки | Допустимость NULL |             По умолчанию
---------+-----------------------+--------------------+-------------------+---------------------------------------
 code    | integer               |                    | not null          | nextval('product_code_seq'::regclass)
 model   | integer               |                    | not null          |
 speed   | smallint              |                    | not null          |
 ram     | smallint              |                    | not null          |
 hd      | real                  |                    | not null          |
 cd      | character varying(10) |                    | not null          |
 price   | numeric(12,2)         |                    |                   |
Индексы:
    "product_pkey" PRIMARY KEY, btree (code)
  • Вопрос задан
  • 94 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы