SQL请求多个选择
SQL请求: 客户的numClient,nomClient,numClient,numTel,订购的总金额 对于prixUnitaire>2000的物品dispendic,prixUnitaire<1500的物品modic总订购量 对于订购大量dispendic文章的客户<订购modic文章的数量 以下是相关的表格SQL请求多个选择,sql,request,Sql,Request,SQL请求: 客户的numClient,nomClient,numClient,numTel,订购的总金额 对于prixUnitaire>2000的物品dispendic,prixUnitaire
- 客户机(numClient、nomClient、numTel)
- 文章(法令、说明、原则、条款)
- 命令(numCde、dateCde、numClient)
- 木质材料(numCde#,numArticle#,qté)
- 利夫莱森(努姆利夫,达特利夫)
- 详细信息(numLiv、numCde、numArticle、qtéLiv)
- 金额是指项目数量(数量),而不是总价值(数量*价格) 该疑问只需要考虑命令,所以“命令”,而不是“LIFRAISY”。
- dispendic指价格>2000;modic表示价格<1500。(我不知道 了解这些词;它们是否特定于您的业务?)
- 我的理解:
create table client
(
num_client integer,
nom_client varchar(16),
num_tel varchar(20),
constraint primary_key_client primary key (num_client)
);
create table article
(
num_article integer,
description varchar(16),
prix_unitaire decimal(9,2),
quantite_en_stock integer,
constraint primary_key_article primary key (num_article)
);
create table commande
(
num_commande integer,
date_commande date,
num_client integer,
constraint primary_key_commande primary key (num_commande),
constraint foreign_key_commande_client foreign key (num_client) references client(num_client)
);
create table ligne_commande
(
num_commande integer,
num_article integer,
quantite integer,
constraint foreign_key_ligne_commande_commande foreign key (num_commande) references commande(num_commande),
constraint foreign_key_ligne_commande_article foreign key (num_article) references article(num_article)
);
insert into client (num_client, nom_client, num_tel) values (123, 'Dubois', '1 41 17 86 62');
insert into client (num_client, nom_client, num_tel) values (456, 'Bochet', '1 35 32 65 58');
insert into article (num_article, description, prix_unitaire, quantite_en_stock) values (79362, 'chaise', 1499.00, 36);
insert into article (num_article, description, prix_unitaire, quantite_en_stock) values (83746, 'placard', 2001.00, 14);
insert into commande (num_commande, date_commande, num_client) values (10030, '2018-01-13', 123);
insert into commande (num_commande, date_commande, num_client) values (10019, '2018-01-12', 456);
insert into ligne_commande (num_commande, num_article, quantite) values (10030, 79362, 4);
insert into ligne_commande (num_commande, num_article, quantite) values (10030, 83746, 1);
insert into ligne_commande (num_commande, num_article, quantite) values (10019, 79362, 1);
insert into ligne_commande (num_commande, num_article, quantite) values (10019, 83746, 1);
insert into ligne_commande (num_commande, num_article, quantite) values (10019, 83746, 1);
质疑
select
a.num_client,
a.nom_client,
a.num_tel,
dispendic.sum_quantite as dispendic_amount,
modic.sum_quantite as modic_amount
from
client a
join
commande b
on a.num_client = b.num_client
join
(
select
num_commande,
sum(quantite) as sum_quantite
from
ligne_commande w
join
article x
on w.num_article = x.num_article
where
x.prix_unitaire < 1500
group by
num_commande
) modic
on b.num_commande = modic.num_commande
join
(
select
num_commande,
sum(quantite) as sum_quantite
from
ligne_commande w
join
article x
on w.num_article = x.num_article
where
x.prix_unitaire > 2000
group by
num_commande
) dispendic
on b.num_commande = dispendic.num_commande
where
dispendic.sum_quantite < modic.sum_quantite;
num_client | nom_client | num_tel | dispendic_amount | modic_amount
------------+------------+---------------+------------------+--------------
123 | Dubois | 1 41 17 86 62 | 1 | 4
(1 row)