q4b :: Day -> Q [(Text, Integer)]
q4b startDate =
  sortWith fst
  $ map (\(view -> (k, g)) -> pair k (length g))
  $ groupWithKey id
    [ o_orderpriorityQ o
    | o <- orders
    , o_orderdateQ o >= toQ startDate
    , o_orderdateQ o < toQ endDate
    , any (\l -> l_commitdateQ l < l_receiptdateQ l
                 && l_orderkeyQ l == o_orderkeyQ o)
          lineitems
    ]
  where
    endDate = C.addGregorianMonthsRollOver 3 startDate
q4b :: Day -> Q [(Text, Integer)]
q4b startDate =
  sortWith fst
  $ map (\(view -> (k, g)) -> pair k (length g))
  $ groupWithKey id
    [ o_orderpriorityQ o
    | o <- orders
    , o_orderdateQ o >= toQ startDate
    , o_orderdateQ o < toQ endDate
    , any (\l -> l_commitdateQ l < l_receiptdateQ l
                 && l_orderkeyQ l == o_orderkeyQ o)
          lineitems
    ]
  where
    endDate = C.addGregorianMonthsRollOver 3 startDate
q4b startDate =
  sortWith fst
  $ map (\(view -> (k, g)) -> pair k (length g))
  $ groupWithKey id
    [ o_orderpriorityQ o
    | o <- orders
    , o_orderdateQ o >= toQ startDate
    , o_orderdateQ o < toQ endDate
    , any (\l -> l_commitdateQ l < l_receiptdateQ l
                 && l_orderkeyQ l == o_orderkeyQ o)
          lineitems
    ]
  where
    endDate = C.addGregorianMonthsRollOver 3 startDate