我有这个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。对不起,如果重复输入。