带有子查询和分组的php mysql查询

I am trying to fill a table with informations out of a query but i am getting error 500. What am I doing wrong?

for($count = 0; $count < $200; $count++)
    {
    $result = mysql_query("SELECT jp.ARTNUM, jp.BEZEICHNUNG, SUM(jp.MENGE), RDATUM
                        FROM journalpos jp, journal j
                        WHERE j.REC_ID=jp.JOURNAL_ID AND ARTNUM IS NOT NULL AND jp.JOURNAL_ID IN
                        (SELECT REC_ID FROM journal WHERE RDATUM BETWEEN NOW() - INTERVAL 1 DAY AND NOW() )
                        GROUP BY ARTNUM 
                        LIMIT $count , 30")
    or die(mysql_error());
    $row = mysql_fetch_array( $result );
    echo "<tr>";
    echo "<td>";
    echo $row['jp.ARTNUM'];
    echo "</td>";

    echo "<td>";
    echo $row['jp.BEZEICHNUNG'];
    echo "</td>";

    echo "<td>";
    echo $row['SUM(jp.MENGE)'];
    echo "</td>";

    echo "<td>";
    echo $row['RDATUM'];
    echo "</td>";
    echo "</tr>";
    }

It worked without the SUM function (then i can leave GROUP BY away) and without the subquery !

One error I found is in this line

for($count = 0; $count < $200; $count++)

$200 is incorrect syntax.

You need to group by the non-aggregate columns in your select - try:

GROUP BY jp.ARTNUM, jp.BEZEICHNUNG, SUM(jp.MENGE), RDATUM

Change this item in the select list to have a name:

SUM(jp.MENGE)

like so:

SUM(jp.MENGE) AS SUM_MENGE

and then use 'SUM_MENGE' in the array in your PHP like so:

 echo $row['SUM_MENGE'];

I expect MySQL is generating a column name for it that is not the one you are using. By choosing the column name, you have control over it and know what it is.