用 left join 把關聯資料表串起來, 並下where constraint篩選出符合條件的資料.
例如要查 3 月份兄弟象每個球員的"每筆單場分數":
select b.*,c.*
from c
left join b on b.bid=c.bid
left join a on a.aid=b.aid
where a.team='兄弟象' and ('0301' <= c.day) and (c.day <= '0331')
另外, 還可用 group by 做統計, 計算出每個球員之單月累計總分
select c.bid,sum(c.point)
from c
left join b on b.bid=c.bid
left join a on a.aid=b.aid
where a.team='兄弟象' and ('0301' <= c.day) and (c.day <= '0331')
group by c.bid
這SQL在phpmyadmin下測試過了, ok.
※ 引述《lottemarines (一平)》之銘言:
: a資料表
: aid team
: 1 兄弟象
: 2 味全龍
: 3 統一獅
: b資料表
: bid player aid
: 1 王大毛 1
: 2 李小虎 1
: 3 陳自強 3
: 4 吳小弟 1
: c資料表
: cid bid day point
: 1 1 0301 10
: 2 1 0302 20
: 3 2 0302 15
: 4 3 0303 -10
: 5 4 0304 -15
: 要怎麼查某一段時間內,兄弟象球員的分數呢?是否跟left right有關呢?
: 感謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.104.191.26