
這里雖然分別篩選了departhub和desthub中重復的資料,但是篩選后的departhub和desthub之間任然有重復的資料,大神們這個該怎么處理啊。
另: departhub和desthub是在表journey里。
算出total后 只想列出那個最大的值。我在count函式前加max的話會報錯“ORA-00937: 不是單組分組函式”。
uj5u.com熱心網友回復:
笨辦法是select name,MAX(TOTAL) FROM (你自己的SQL) group by name
uj5u.com熱心網友回復:
我理解的不知道有沒有問題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
);
uj5u.com熱心網友回復:
把你的需求再明確下,最好有模擬資料及預期結果轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/93525.html
標籤:高級技術
上一篇:proc程式,oracle資料庫,在proc程式中出現游標:Fetch cursor Error(-1001)
下一篇:12C中單步除錯報錯 求大俠幫忙
