这里虽然分别筛选了departhub和desthub中重复的数据,但是筛选后的departhub和desthub之间任然有重复的数据,大神们这个该怎么处理啊。另: departhub和desthub是在表journey里。算出total后 只想列出那个最大的值。我在count函数前加max的话会报错“ORA-00937: 不是单组分组函数”。

解决方案 »

  1.   

    笨办法是
    select name,MAX(TOTAL) FROM (你自己的SQL) group by name
      

  2.   

    我理解的不知道有没有问题 
    departhub  distinct 后数据是 123   count后是3
    desthub      distinct  后数据 是 345 count后是3
    total 后是 6
    你想要的是   distinct 这两列后   是12345 要的 total 是 5
    如果理解没问题  sql如下
    select  traveller.givenname||''||traveller.familyname as name,
    traveller.travellerid,count (distinct j.departAll) as total
    from traveller , (
    select journeyid,travellerid,departhub as departAll from journey
    union all
    select journeyid,travellerid,desthub  from journey
    ) j, reservation
    where j.journeyid = reservation.journeyid and traveller.travellerid = reservation.travellerid
    group by  traveller.givenname||''||traveller.familyname,traveller.travellerid;
    select max(total) from (
    上述sql
    );