这是我的疑问:
SELECT
`date`,
MAX(IF(`index_name` = 'Alerian MLP PR USD' AND `time_period`='M1', results, NULL)) AS `Alerian MLP PR USD`,
MAX(IF(`index_name` = 'MSCI EAFE Mid NR USD' AND `time_period`='M1', results, NULL)) AS `MSCI EAFE Mid NR USD`
FROM
`mst_ind`
GROUP BY `date`
问题是它返回多个NULL值,如
我可以将该查询包装在另一个查询中,如
SELECT * FROM (
SELECT
`date`,
MAX(IF(`index_name` = 'Alerian MLP PR USD' AND `time_period`='M1', results, NULL)) AS `Alerian MLP PR USD`,
MAX(IF(`index_name` = 'MSCI EAFE Mid NR USD' AND `time_period`='M1', results, NULL)) AS `MSCI EAFE Mid NR USD`
FROM
`mst_ind`
GROUP BY `date`
) sel
WHERE sel.`MSCI EAFE Mid NR USD` IS NOT NULL AND sel.'Alerian MLP PR USD' IS NOT NULL
但这不是一个好的解决方案,因为我必须列出“NOT NULL”子句中的所有字段。
这里有更简单的消除NULL值的方法吗?
谢谢!