N
N
Nodir Malikov2020-12-22 08:54:36
SQL
Nodir Malikov, 2020-12-22 08:54:36

SQL, multiple conditions when selecting, how to do it right?

I have to display products from tables in which 1 and 3 join with join and which have speed>750
But speed in PC shows correctly under the condition and Laptop does not.

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 structure:
Таблица "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)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question