Facebook
From Morose Panda, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 73
  1. -- 10
  2. SELECT
  3. c.countrykey, c.countryname
  4. FROM orderheader oh
  5. INNER JOIN country c ON oh.countrykey = c.countrykey
  6. INNER JOIN orderstatus os ON oh.orderstatuskey=os.orderstatuskey
  7. WHERE os.orderstatusname like 'Finished'
  8. GROUP BY c.countrykey, c.countryname
  9. HAVING COUNT(*) =
  10. (
  11.  SELECT DISTINCT
  12.  MAX(orders)
  13.  FROM
  14.  (
  15.  SELECT DISTINCT
  16.  COUNT(*) orders
  17.  FROM orderheader oh
  18.  INNER JOIN orderstatus os ON oh.orderstatuskey=os.orderstatuskey
  19.  WHERE os.orderstatusname like 'Finished'
  20.  GROUP BY oh.countrykey
  21.  )
  22. );
  23.