从查询DB2选择最大日期

时间:2018-08-09 08:13:02

标签: sql db2

如何从以下查询中选择最大/最大日期?

SELECT 
s.PROFILENUMBER AS profile
a.AUTHTYPE AS authorization_type,
to_char(date(a.wr), 'yyyymmdd') AS ts_vf,
to_char(date(c.wr), 'yyyymmdd') AS ts_vf,
to_char(date(s.wr), 'yyyymmdd') AS ts_vf,
FROM ssn_an_auth a,
ssn_an_spac_c c,
ssn_an_salesprofile s
where a.id = c.aaid
and s.id = c.ssid 

1 个答案:

答案 0 :(得分:0)

怎么样?

SELECT MAX(MAX(a_wr,c_wr,s_wr)) AS "largest / maximum date" FROM (
    SELECT 
    s.PROFILENUMBER AS profile,
    a.AUTHTYPE AS authorization_type,
    date(a.wr) a_wr,
    date(c.wr) c_wr,
    date(s.wr) s_wr
    FROM ssn_an_auth a,
    ssn_an_spac_c c,
    ssn_an_salesprofile s
    where a.id = c.aaid
    and s.id = c.ssid
)