join - (Newbie) MySQL View -
i'm new sql , going wrong way help?
i need create view in mysql can't figure out how combine these 2 sql statements, views not accept multiple selects or variables.
nb: second statement works when replacing @numberofgames var correct number (manually calculated).
first statement - return total number of games year:
select count( id ) @numberofgames tblgames gdate '2014%'; second statement - create view data:
select p.player player, count( c.gid ) gamecount, sum( c.cash ) cash, round( avg( c.cash ), 2 ) avg, sum( ( case when ( c.wotn > 0 ) c.wotn else 0 end ) ) wotn, sum( ( case when ( c.cash > 0 ) c.cash else 0 end ) ) cashwon, sum( ( case when ( c.cash < 0 ) c.cash else 0 end ) ) cashlost, round( avg( ( case when ( c.cash >= 0 ) c.cash end ) ),2 ) avgwin, round( avg( ( case when ( c.cash < 0 ) c.cash end ) ),2 ) avgloss, if( ( ( count( c.pid ) > ( @numberofgames / 3 ) ) , ( count( c.pid ) > 2 ) ), round( ( ( avg( c.cash ) * 10 ) + 200 ), 2 ), round( avg( c.cash ), 2 ) ) sortingpoints tblplayers p left join tblcash c on p.id = c.pid left join tblgames g on g.id = c.gid c.cash not null , g.gdate '2014%' group c.pid order sortingpoints desc; i'm using @numberofgames vars simple maths equation checks player has played more third of total games in year.
i hope can point me right direction.
you missing point of view does.
can't save multiple statements in 1 view. it's trying save 2 tables in 1 table. it's not possible.
what need is, run first select, have it. save view. can use result set if other live table, , join other tables in subsequent select statements.
Comments
Post a Comment