Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select *
- from (
- select
- DP.port_id,
- S.ship_id,
- count(S.ship_id) as Cnt,
- V.voyage_id
- from Captain_Ship_Voyage as CSV
- inner join Voyage as V on V.voyage_id = CSV.voyage_id
- inner join DestPoint as DP on DP.voyage_id = V.voyage_id
- inner join Ship as S on S.ship_id = CSV.ship_id
- group by Dp.port_id, S.[name], S.ship_id, V.voyage_id
- ) as tmptmt
- where
- Cnt = (
- select max(Cnt)
- from (
- select
- count(ISh.ship_id) as Cnt
- from Captain_Ship_Voyage as ICSV
- inner join Voyage as IV on IV.voyage_id = ICSV.voyage_id
- inner join DestPoint as IDP on IDP.voyage_id = IV.voyage_id
- inner join Ship as ISh on ISh.ship_id = ICSV.ship_id
- where
- IV.voyage_id = tmptmt.voyage_id
- group by IDp.port_id, ISh.[name], ISh.ship_id
- ) as tmpp
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement