Table orderlinesTable = schema.getTableByName("orderlines");
Column commonProdIdColumn = orderlinesTable.getColumnByName("prod_id");
Column quantityColumn = orderlinesTable.getColumnByName("quantity");
q.from(orderlinesTable);
q.where(new FilterItem(new SelectItem(prodIdColumn), OperatorType.EQUALS_TO, new SelectItem(commonProdIdColumn)));
q.groupBy(titleColumn);
q.getSelectClause().removeItem(q.getSelectClause().getSelectItem(productPriceColumn));
SelectItem quantitySum = new SelectItem(FunctionType.SUM, quantityColumn).setAlias("orderAmount");
q.select(quantitySum);
q.having(new FilterItem(quantitySum, OperatorType.GREATER_THAN, 25));
q.orderBy(new OrderByItem(q.getSelectClause().getItem(0)));
assertEquals("SELECT \"products\".\"title\" AS product-title, SUM(\"orderlines\".\"quantity\") AS orderAmount "
+ "FROM public.\"products\", public.\"orderlines\" "
+ "WHERE \"products\".\"prod_id\" = \"orderlines\".\"prod_id\" " + "GROUP BY \"products\".\"title\" "