If within If ?

If within If ?

am 19.10.2010 15:01:04 von Tompkins Neil

--20cf3005dcd2ae387c0492f7e251
Content-Type: text/plain; charset=ISO-8859-1

Hi,

I've the following query :

SELECT IFNULL(SUM(gate_receipts),0) AS gate_receipts, competitions.caption
FROM fixtures_results
INNER JOIN competitions ON fixtures_results.competitions_id =
competitions.competitions_id
WHERE home_teams_id = 27
AND worlds_id = 1 AND status = 'approved'

However, I want to check the value of competitions.competition_type and if
it is 'cup' I want to divide the value of gate_receipts by 2. How is the
best way to achieve this ?

Regards
Neil

--20cf3005dcd2ae387c0492f7e251--

Fwd: If within If ?

am 19.10.2010 17:50:05 von Tompkins Neil

--0015175cddd821bf5f0492fa3fbc
Content-Type: text/plain; charset=ISO-8859-1

Hi,

I think I've managed to do it :

SELECT
IF(competitions.competition_type = 'cup',
IFNULL(ROUND(SUM(gate_receipts)/2),0), IFNULL(SUM(gate_receipts),0))AS
gate_receipts
FROM fixtures_results
INNER JOIN competitions ON fixtures_results.competitions_id =
competitions.competitions_id
WHERE home_teams_id = 27
AND worlds_id = 1 AND status = 'approved'

Cheers
Neil


---------- Forwarded message ----------
From: Tompkins Neil
Date: Tue, Oct 19, 2010 at 2:01 PM
Subject: If within If ?
To: "[MySQL]"


Hi,

I've the following query :

SELECT IFNULL(SUM(gate_receipts),0) AS gate_receipts, competitions.caption
FROM fixtures_results
INNER JOIN competitions ON fixtures_results.competitions_id =
competitions.competitions_id
WHERE home_teams_id = 27
AND worlds_id = 1 AND status = 'approved'

However, I want to check the value of competitions.competition_type and if
it is 'cup' I want to divide the value of gate_receipts by 2. How is the
best way to achieve this ?

Regards
Neil

--0015175cddd821bf5f0492fa3fbc--