0
我需要重寫下面的查詢使用「與」,以便它不再使用「與」,但我不知道該怎麼辦它正好。我被告知使用子查詢,但我的嘗試沒有奏效。如何轉換一個SQL「與」,以便它不使用「與」
下面是我需要轉換:
with
best (cid, title, year, lowest) as (
select distinct M.cid, O.title, O.year, min(price)
from yrb_member M, yrb_purchase P, yrb_offer O
where M.club = O.club and
M.cid = P.cid and
P.title = O.title and P.year = O.year
group by M.cid, O.title, O.year
)
select C.name, P.title, P.year, qnty, price, lowest
from yrb_customer C, yrb_purchase P, Best B, yrb_offer O
where P.cid = B.cid and P.title = B.title and
P.year = B.year and P.title = O.title and
P.year = O.year and P.club = O.club and
C.cid = P.cid and
O.price > B.lowest
order by C.name, P.title, P.year;
我試圖複製的部分用語句改成where語句,但我收到一個錯誤說「標量全查詢的結果,SELECT INTO語句,或VALUES INTO語句不止一行。「您可以在下面看到我的嘗試(它仍然使用「with」,但我試圖替換一小部分,以查看是否可以在查詢的其餘部分使用相同的技術最終完全刪除「with」語句):
with
best (cid, title, year, lowest) as (
select distinct M.cid, O.title, O.year, min(price)
from yrb_member M, yrb_purchase P, yrb_offer O
where M.club = O.club and
M.cid = P.cid and
P.title = O.title and P.year = O.year
group by M.cid, O.title, O.year
)
select distinct C.name, P.title, P.year, qnty, price, lowest
from yrb_customer C, yrb_purchase P, Best B, yrb_offer O
where P.cid =
(select distinct M.cid
from yrb_member M, yrb_purchase P, yrb_offer O
where M.club = O.club and
M.cid = P.cid and
P.title = O.title and P.year = O.year
)
and P.title = B.title and
P.year = B.year and P.title = O.title and
P.year = O.year and P.club = O.club and
C.cid = P.cid and
O.price > B.lowest
order by C.name, P.title, P.year;
您好!我想你會見我的一位朋友,他的名字是'join'。看看他的個人資料:https://technet.microsoft.com/en-us/library/ms191472(v=sql.105).aspx –
只需在「from」子句中用逗號「no」表示。 –