這些都是創建的表,我有工作:SQL SELECT查詢語句
create table Customer2 (
cid char(3), cname char(10), primary key (Cid)
);
create table Employee2 (
eid char(3), ename char(10), salary number(7,2), mid char(3),primary key (eid), foreign key (mid) references Employee2
);
create table ArtObject2 (
aoid char(3), atitle char(12), artist varchar(10), pricea number(8,2), primary key (aoid)
);
create table MakesD2 (
aoid char(3), eid char(3), cid char(3), prices number, dates date, primary key (aoid,CID), foreign key (aoid) references ArtObject2, foreign key (CID) references Customer2, foreign key (eid) references Employee2
);
我需要寫下面的SQL語句:
- 名單的客戶誰沒有購買任何名稱繪畫與要價 高於$ 500,000.00
- 找到誰買了最高數量的畫的客戶的名字
- 對於每一幅畫ld顯示該畫的標題,由顧客支付的價格 以及如果以高於平均要價的價格出售的繪畫以及如果繪畫出售在繪畫上的話「低於平均」 價格低於平均要價。對於持有「要求高於 」或「低於要求」等字的列製作標題備註。
我想這種說法對#1,但沒有結果過多:
select cname from customer2
where cid in (select cid from makesd2
where aoid in (select aoid from artobject2
where pricea <= '500000'));
我想這個語句#2,但沒有返回結果:
select c.cname from customer2 c
inner join(select cid, count(*) as bought
from makesd2
group by cid m on m.cid = c.cid
order by m.bought;
我試着這個聲明爲#3和它的工作,它只是錯過了應該是'春'的第一個結果:
select a.atitle, m.prices, 'Higher than average' as "Price" from artobject2 a
join makesd2 m on
a.aoid = m.aoid
and a.pricea > (select avg(pricea) from artobject2)
union
select a.atitle, m.prices, 'Lower than average' as "Price" from artobject2 a
join makesd2 m on
a.aoid = m.aoid
and a.pricea <= (select avg(pricea) from artobject2);
沒有冒犯,但我們都可以同意這個標題是可怕的嗎?當然,我不知道如何解決它。 –
更改爲「請爲我完成作業。」 – catfood
敵人#3,你說過「如果這幅畫的價格比平均要價貴」。整個ArtObject2表的平均價格是多少? – Shiva