下面是我的 sql 语句,一切正常,只是我不知道如何从多个返回值中找到 MAX。无论如何,这是我的代码,我有问题的部分用 [] 标记。
SELECT
(product1.CNT+product2.CNT+product3.CNT)AS CNT,
(
IFNULL(product1.SUMAMT,0)+
IFNULL(product2.SUMAMT,0)+
IFNULL(product3.SUMAMT,0)
)AS AMTAMT,
[ MAX(product1.MXDT, product2.MXDT, product3.MXDT)AS MAXDT]
FROM
(SELECT
SUM(LAMT)AS SUMAMT,
COUNT(LAMT)AS CNT,
IFNULL(LSUBDT,(CURDATE()-INTERVAL 9999 DAY))AS MXDT
FROM product1 WHERE LSUBBY=1 AND RECST=1
)product1
CROSS JOIN
(SELECT
SUM(LAMT)AS SUMAMT,
COUNT(LAMT)AS CNT,
IFNULL(LSUBDT,(CURDATE()-INTERVAL 9999 DAY))AS MXDT
FROM product2 WHERE LSUBBY=1 AND RECST=1
)product2
CROSS JOIN
(SELECT
SUM(LAMT)AS SUMAMT,
COUNT(LAMT)AS CNT,
IFNULL(LSUBDT,(CURDATE()-INTERVAL 9999 DAY))AS MXDT
FROM product3 WHERE LSUBBY=1 AND RECST=1
)product3