0

我正在尝试garage_list:account_id 从那里获取 1 个实例的计数并获取对应player_list:account_idgarage_list:tank_idtank_list:tank_id

茶几将如下所示:

坦克 :: 计数(玩家计数的替代文字)

IS-3 :: 2 --> (玩家 1, 玩家 3)

E-100 :: 3 --> (player1, player 4, player 9)

Select Count(Distinct tank_id) As 
    counttanks , 
    Count(tank_id) As 
    counttanks ,
tank_id As tank_id From garage_list 



   RIGHT JOIN player_list 
        ON player_list.account_id = garage_list.account_id

   RIGHT JOIN tank_list 
        ON player_list.tank_id = tank_list.tank_id 

     Group By tank_id

  where tank_list.level='8',
  and player_list.clan='BAD-1'
  and player_list.account_id = '500549663'



  TABLES  
<garage_list>
account_id :: tank_id
1234       ::   20
1234       ::    44
4321       ::   18

    <tank_list>
    Tank_id :: name :: long_name :: row1 :: row2 :: row3 ::
    20     :: sherman::usa_sher

    <player_list>
    account_id :: clan :: nickname
    1234        ::bad-1:: joker
    4321       ::bad-g :: grumpy
4

1 回答 1

0

所以从我收集的信息来看,你会想要这样的东西:

select pc.NumOfPlayers, tl.tank_id, pl.account_id, pl.clan, pl.nick
  from tank_list tl
  inner join garage_list gl
             on  tl.tank_id = gl.tank_id
  inner join player_list pl
             on gl.account_id = pl.account_id
  inner join (select tank_id, 
                     count(*) as NumOfPlayers 
                from garage_list group by tank_id) as pc
              on tl.tank_id = pc.tank_id
order by tl.tank_id

查看 SQL 小提琴

于 2015-10-05T19:07:21.500 回答