I have a problem with an sql query with php, I need to calculate the total of units sold by vendor, I am limiting the number of records to show because the database has hundreds of records, and I am just trying out the query.
But when making the query I get these two errors:
Warning: odbc_exec (): SQL error: [TOD] [ODBC] [GENESIS] Non aggregates require a GROUP BY expression.
Warning: odbc_fetch_row () expects parameter 1 to be resource, boolean given in
This is my code:
<?php
$sqlVend = "SELECT TOP 10 VEN_LLAVE, VEN_NOMBRE, SUM(VDOC_UDS) AS Suma,
from VENVEN, VENDOC
where VENVEN.VEN_LLAVE = VENDOC.VDOC_VEND GROUP BY VEN_LLAVE, VEN_NOMBRE";
$resVend = odbc_exec($cone, $sqlVend);
while (odbc_fetch_row($resVend)) {
# code...
?>
<tr>
<td><?php echo odbc_result($resVend, 'VEN_LLAVE') ?></td>
<td><?php echo odbc_result($resVend, 'VEN_NOMBRE') ?></td>
<td><?php echo odbc_result($resVend, 'Suma') ?></td>
</tr>
<?php } ?>