我有这个 MYSQL 查询:
SELECT
time_of_day as time,
player_date as date ,
CASE max(case when rownum = 1 then player_value end) WHEN 'P' THEN 'P' WHEN 'E' THEN 'P[' ELSE ' ' END as TMZH ,
CASE max(case when rownum = 2 then player_value end) WHEN 'P' THEN 'P' WHEN 'E' THEN 'P[' ELSE ' ' END as BLAK
FROM (
select
player_date,
time_of_day,
player_value,
player_cid,
@row:=case when @prev=player_date then @row else 0 end + 1 as rownum,
@prev:=player_date
from (
select
t1.player_date,
t1.player_value,
t1.time_of_day ,
t2.player_cid
from
availability t1
inner join players t2 on t1.player_id = t2.player_id
order by player_date, player_cid
) d,
(SELECT @row:=0, @prev:=null) r
order by player_date, player_cid
) src
WHERE
YEAR(player_date) = YEAR(NOW())
group by
player_date,
time_of_day
我得到这样的结果(摘录):
time date TMZH BLAK
...
am 2013-06-03 P[
pm 2013-06-03 P
am 2013-06-04 P
pm 2013-06-04 P[
am 2013-06-05
pm 2013-06-05
...
并且这些值应该只在 TMZH 列中,因为它们的可用性表条目具有键 1,当前该表中的所有条目都具有键 1(对应于 TMZH player_cid 字段)。
知道是什么原因造成的吗?
PS。抱歉,如果重复输入。