我对我的SELECT感到困惑:
SELECT
mergedData.rawValue,
mergedData.validatedValue,
IFNULL(mergedData.validatedValue, mergedData.rawValue) as mergedValue
FROM
[...]
当mergedData.rawValue
和mergedData.validatedValue
返回DOUBLE时,IFNULL
语句返回BLOB。为什么会这样?我怎样才能让它返回DOUBLE呢?
编辑:
我通过模拟FULL JOIN
合并了两个在我的Select中具有完全相同结构的表。数据在两个表中都存储为DOUBLE:
TableRawData(NOX加载到mergedData.rawValue中):
timed (BIGINT(20)) --- NOX (DOUBLE)
1380583800000 8.972167
TableValidatedData(NOX加载到mergedData.validatedValue中):
timed (BIGINT(20)) --- NOX (DOUBLE)
1380583800000 9.506166
EDIT2:我的完整选择:
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
答案 0 :(得分:1)
投下它
SELECT
mergedData.rawValue,
mergedData.validatedValue,
CAST(IFNULL(mergedData.validatedValue, mergedData.rawValue) AS DECIMAL[(M[,D])]) as mergedValue
FROM
请注意DECIMAL[(M[,D])]
您应该在定义表时填写它。
编辑,COALESCE
也可能很有趣。示例用法;
SELECT
mergedData.rawValue,
mergedData.validatedValue,
COALESCE(mergedData.validatedValue, mergedData.rawValue) as mergedValue
FROM
Perheps你不需要再施展