/*-------------temp table--------------*/
CREATE TEMPORARY TABLE IF NOT EXISTS bowlpick.tempschedule AS
(SELECT * FROM bowlpick.schedule
where season = (select max(year) from bowlpick.season));
/*-------------temp table--------------*/
set @g1= (select winner from bowlpick.tempschedule where game =1);
select date,name, @g1,bowl1 Pick,comf1
,case
when bowl1 = @g1 then comf1
when bowl1 <> @g1 then -comf1
else '0' end pts
from bowlpick.picks
where year(date) = (select max(year) from bowlpick.season)
order by bowl1 desc limit 5
<--------------------Table----------------->
name @g1 Pick comf1 pts
Player 1 Boise State Washington 7 -7
Player 2 Boise State Boise State 30 -30
Player 3 Boise State Boise State 21 -21
Player 4 Boise State Boise State 27 -27
Player 5 Boise State Boise State 15 -15
为什么这不起作用???最后四个点应该是正数,而不是负数。就好像变量(@g1)在“CASE”部分不起作用。当“选择”部分时它可以正常工作。如果我对获胜者(博伊西州)进行硬编码,它会正常工作。变量在 case 语句中不起作用吗?