
 SELECT
                                                                             n_name  AS  nation,
                                                   EXTRACT( YEAR FROM od_orderdate)  AS  o_year,
         SUM (lep_extendedprice * (1 - ld_discount) - psc_supplycost * lq_quantity)  AS  sum_profit
   FROM
         p_name,
         ps_supplycost,
         lineitem TABLE OPTION (index r_l_pksk), 
         l_extendedprice, 
         l_quantity, 
         l_discount,
         o_orderdate,
         s_nationkey,
         nation
   WHERE 
            snk_suppkey = l_suppkey
     AND    psc_suppkey = l_suppkey
     AND    psc_partkey = pn_partkey
     AND     pn_partkey = l_partkey
     AND    od_orderkey = l_orderkey
     AND  snk_nationkey = n_nationkey
     AND  pn_name LIKE '%green%'
     AND     l_orderkey = lep_orderkey 
     AND   l_linenumber = lep_linenumber
     AND     l_orderkey = lq_orderkey 
     AND   l_linenumber = lq_linenumber
     AND     l_orderkey = ld_orderkey 
     AND   l_linenumber = ld_linenumber

GROUP BY
          nation,
          o_year
ORDER BY
          nation,
          o_year DESC
  OPTION  (order, loop);
