select
   {np_sort} as mhn,
   {if(np_ska, 1, 0)} as kat,
   d01.p03 as p02,
   d01.p06 as p06,
sum(d01.p311) as p04,
   d02.p02 as vp06
FROM d01
LEFT JOIN d02 ON d01.p06 = d02.p01
WHERE d01.p05={p_t00eid}
   && d01.p07={p_t00sko}
   && d01.p03>='{odbcdtos(np_df)}'
   && d01.p03<='{odbcdtos(np_dt)}'
GROUP BY {p_t00fld1} {p_t00fld2} ;

