Hi
I am trying to create a View in my DB using an IF statement in my SELECT section of the CREATE VIEW statement, but the results I achieve seem to be very random.
I have a table with football teams in it with scores for each team. I want to now create some views so that the league table will automatically update based on info in the MATCHES table. I thought I would do this using a VIEW to create the points, then another view to add the points, etc.
Here's my CREATE VIEW statement:
When I view the `homeresults` VIEW, I would expect that any team which has a higher `htot` would have 3 points, a draw (`htot`=`atot`) would have 1 point, otherwise 0 points.
But the points allocated in the VIEW seems very random. Some are correct, but on the whole the VIEW seems not to be following my logic.
Any help?
I am trying to create a View in my DB using an IF statement in my SELECT section of the CREATE VIEW statement, but the results I achieve seem to be very random.
I have a table with football teams in it with scores for each team. I want to now create some views so that the league table will automatically update based on info in the MATCHES table. I thought I would do this using a VIEW to create the points, then another view to add the points, etc.
Here's my CREATE VIEW statement:
Code:
CREATE VIEW homeresults AS
SELECT `home`,`htot`,`away`,`atot`,
if(`htot`=`atot`,1,if(`htot`>`atot`,3,0)) AS `Pts`
FROM `matches` WHERE `date` < NOW();
But the points allocated in the VIEW seems very random. Some are correct, but on the whole the VIEW seems not to be following my logic.
Any help?