I'm a PHP novice and I am having trouble getting a MSSQL query right.
My original query works, but when I try to limit the response to "Orders" that total less than 100 I get errors and I do not understand them.
This works:
$query = "SELECT OEORDLIN_SQL.ord_no, SUM(OEORDLIN_SQL.qty_ordered*OEORDLIN_SQL.unit_price) as ordertot FROM OEORDLIN_SQL WHERE OEORDLIN_SQL.request_dt='20031010' GROUP BY OEORDLIN_SQL.ord_no";
This is my attempt to limit the result to "Orders" that total less than 100
$query = "SELECT OEORDLIN_SQL.ord_no, SUM(OEORDLIN_SQL.qty_orderedOEORDLIN_SQL.unit_price) as ordertot FROM OEORDLIN_SQL WHERE OEORDLIN_SQL.request_dt='20031010' AND (SUM(OEORDLIN_SQL.qty_orderedOEORDLIN_SQL.unit_price)<100) GROUP BY OEORDLIN_SQL.ord_no";
This is the error I get when I run the above query:
Warning: mssql_query(): message: An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.