这是我的查询:
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 值?
谢谢!