Mysql Select Correlation 2 Levels深度子查询

时间:2018-11-26 02:05:44

标签: mysql

我被困住了,这让我发疯了...我想使用下面的代码来获得x胜数。问题是,mysql仅允许1个关联级别(不确定im能否解释此权利),但是-[UIFontMetrics scaledFontForFont:]应该从第一个选择查询中返回玩家ID。关于如何进行这项工作的任何想法吗?

@id

以下是一些示例数据:

(使用动态@id别名无效) https://www.db-fiddle.com/f/ao2zgyiy8U5doGER6XZT23/3

(使用静态ID 8可以正常工作) https://www.db-fiddle.com/f/2f2KvZt5MHVUuaP3WLPmAi/2

以下是输出结果:

    select (@rank := if(@points = points, @rank +1, if(@points := points, @rank + 1, @rank + 1 ))) as rank, er.* from (select
@id := cc6_MensLeague_players.id as `id`,
@rounds := (
ifnull((select sum(p1.w)
from (
select 
@r1 := (case when p1_r1 like '%' then 1 else 0 end) as r1,
@r2 := (case when p1_r2 like '%' then 1 else 0 end) as r2,
@r3 := (case when p1_r3 like '%' then 1 else 0 end) as r3,
@r4 := (case when p1_r4 like '%' then 1 else 0 end) as r4,
(@r1+@r2+@r3+@r4) as w
from cc6_MensLeague_scoresheets where p1 = @id
)p1),0)
) as `rounds`,
sum((@rounds*2)+(@rounds*1)) as `points`
from cc6_MensLeague_players group by `id`) er cross join (select @rank := 0, @points := -1) params order by id desc limit 9;

感谢您的帮助

0 个答案:

没有答案