比较两三个字段的最大值
SELECT d.id, (SELECT MAX(maxtimes) FROM ( VALUES ( d.t1), ( d.t2), ( d.t3) ) AS times ( maxtimes ) ) AS times FROM( SELECT a.times AS t1, b.times AS t2,c.times AS t3,a.id FROM a LEFT JOIN b ON b.id = a.id LEFT JOIN b ON a.id = c.id ) d
SELECT d.id, (SELECT MAX(maxtimes) FROM ( VALUES ( d.t1), ( d.t2), ( d.t3) ) AS times ( maxtimes ) ) AS times FROM( SELECT a.times AS t1, b.times AS t2,c.times AS t3,a.id FROM a LEFT JOIN b ON b.id = a.id LEFT JOIN b ON a.id = c.id ) d