MrLine
MrLine

Reputation: 688

Invalid use of group function - #1111

I have two tables

Table verkoper

enter image description here

Table bestellingen

enter image description here

My Query:

  SELECT v.naam, 
         SUM(COUNT(b.status) * 1.50)
    FROM verkoper AS v INNER JOIN 
         bestellingen AS b ON b.verkoper = v.id
   WHERE b.status = 'retour'
GROUP BY b.verkoper

It gives me the error #1111 - Invalid use of group function Anyone an idea?

Upvotes: 0

Views: 66

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269443

I think this might be what you want:

SELECT v.naam, COUNT(*)*1.50
FROM verkoper v INNER JOIN
     bestellingen b
     ON b.verkoper = v.id
WHERE b.status = 'retour'
GROUP BY v.naam;

Notes:

  • The GROUP BY keys should match the unaggregated columns in the query.
  • You can count all rows using COUNT(*) or COUNT(1). This is simpler to type.
  • There is no reason to nest COUNT() inside SUM().

Upvotes: 2

Related Questions