0

任何人都可以告诉我如何制作多个左连接的视图吗?

A GAME has zero or multiple LINKs (OneToMany on GAME.ID = LINK.GAME_ID)
Each LINK has exactly one of multiple STOREs (OneToOne on LINK.STORE_ID = STORE.ID)
Each STORE has exactly one of multiple PLATFORMs (OneToOne on STORE.PLATFORM_ID = PLATFORM.ID)

我想把 VIEW 作为

PLATFORM_ID (FK)    GAME_ID (FK)
--------------------------------

我的意思是我想GAME通过给定的 s 列出 s,PLATFORM每个都至少有一个或多个路径通过LINKSTORE到达PLATFORM

谢谢你。

4

3 回答 3

3
select 
   l.game_id, p.platform_id
from
   links l,
   stores s,
   platforms p
where
   l.link_id = s.link_id
and
   p.platform_id = s.platform_id
group by 
   l.game_id, p.platform_id
于 2012-07-04T05:31:24.200 回答
2
SELECT DISTINCT s.PLATFORM_ID, l.GAME_ID
FROM Games g 
LEFT JOIN Links l ON g.ID = l.GAME_ID
INNER JOIN Stores ON l.STORE_ID = s.STORE_ID
INNER JOIN PLATFORMS p ON s.PLATFORM_ID = p.ID
于 2012-07-04T05:28:56.110 回答
1

你的 SQL 将是,

select GAME_ID 
from GAME,STORE,PLATFORM
where 
PLATFORM.ID = STORE.PLATFORM_ID
and STORE.ID = GAME.STORE_ID
and PLATFORM.ID = {some_ID}
于 2012-07-04T05:29:26.870 回答