这不是MAX()
聚合函数在 TSQL 中的工作方式(参见此处:TSQL MAX()) MAX 函数仅在单个列中获取最大值。
要在此处实现您想要的,您必须将三个值放入单个列中。这可以使用UNPIVOT
PIVOT/UNPIVOT来完成
这个片段可能会帮助你。
CREATE TABLE #A (ID INT, tickvalue INT)
CREATE TABLE #B (ID INT, tickvalue INT)
CREATE TABLE #C (ID INT, tickvalue INT)
INSERT INTO #A VALUES (1,1)
INSERT INTO #A VALUES (2,4)
INSERT INTO #A VALUES (3,7)
INSERT INTO #A VALUES (4,2)
INSERT INTO #A VALUES (5,8)
INSERT INTO #B VALUES (1,8)
INSERT INTO #B VALUES (2,7)
INSERT INTO #B VALUES (3,2)
INSERT INTO #B VALUES (4,4)
INSERT INTO #B VALUES (5,1)
INSERT INTO #C VALUES (1,2)
INSERT INTO #C VALUES (2,1)
INSERT INTO #C VALUES (3,2)
INSERT INTO #C VALUES (4,15)
INSERT INTO #C VALUES (5,2)
SELECT ID, MAX(tickvalue)
FROM
(SELECT C.ID, A.tickvalue t1, B.tickvalue t2, C.tickvalue t3
FROM #A AS a
JOIN #B AS b ON a.ID = b.ID
JOIN #C AS c ON b.ID = c.ID) p
UNPIVOT (tickvalue FOR tsource IN (t1,t2,t3)) AS unpvt
GROUP BY ID
DROP TABLE #A
DROP TABLE #B
DROP TABLE #C