I am having some confusion with my SELECT:
SELECT
mergedData.rawValue,
mergedData.validatedValue,
IFNULL(mergedData.validatedValue, mergedData.rawValue) as mergedValue
FROM
[...]
While mergedData.rawValue
and mergedData.validatedValue
return as DOUBLE, the IFNULL
statement returns a BLOB. Why is that happening? And how can I make it return a DOUBLE instead?
EDIT:
I am merging two tables that have exactly the same structure in my Select by emulating a FULL JOIN
. The data is stored as a DOUBLE in both tables:
TableRawData (NOX gets loaded into mergedData.rawValue):
timed (BIGINT(20)) --- NOX (DOUBLE)
1380583800000 8.972167
TableValidatedData (NOX gets loaded into mergedData.validatedValue):
timed (BIGINT(20)) --- NOX (DOUBLE)
1380583800000 9.506166
EDIT2: My full SELECT:
SET @StartTime = 1356998400000;
SET @EndTime = 1386546000000;
SELECT
mergedData.rawValue,
mergedData.validatedValue,
CAST(IFNULL(mergedData.validatedValue, mergedData.rawValue) AS DECIMAL(10, 5)) as mergedValue
FROM
(SELECT
Month(FROM_UNIXTIME(timed / 1000)) as months,
Year(FROM_UNIXTIME(timed / 1000)) as years,
DAYOFMONTH(FROM_UNIXTIME(timed / 1000)) as days,
HOUR(FROM_UNIXTIME(timed / 1000)) as hours,
MINUTE(FROM_UNIXTIME(timed / 1000)) as minutes,
IF(true, avg(NOX), null) as rawValue,
FROM_UNIXTIME(timed / 1000) as timeValue,
IF(true, 1, 0) as IsValid,
NULL as validatedValue
FROM
nabelnrt_bas
WHERE
timed > @StartTime
AND timed < @EndTime
GROUP BY concat(years, months, days) UNION (
SELECT
Month(FROM_UNIXTIME(timed / 1000)) as months,
Year(FROM_UNIXTIME(timed / 1000)) as years,
DAYOFMONTH(FROM_UNIXTIME(timed / 1000)) as days,
HOUR(FROM_UNIXTIME(timed / 1000)) as hours,
MINUTE(FROM_UNIXTIME(timed / 1000)) as minutes,
IF(true, avg(NOX), null) as validatedValue,
FROM_UNIXTIME(timed / 1000) as timeValue,
IF(true, 1, 0) as IsValid,
NULL as rawValue
FROM
nabelvalidated_bas
WHERE
timed > @StartTime
AND timed < @EndTime
GROUP BY concat(years, months, days))) as mergedData