hafizy Baharudin
hafizy Baharudin

Reputation: 87

MySql Group By and Sum total value of column, displayed with min value

I have two questions:

  1. How to group and sum a column.
  2. How to displayed the result with a min sum value

I got my 1st answer here on how to group and sum the column, but I need to filter out by min amount of 100 ..

I tried

SELECT 
    member_code, SUM(product_price) as totalSales
FROM 
    src_calculation_daily
WHERE 
    totalSales > 100
GROUP BY 
    member_code

Any help is much appreciated. Thank you

Upvotes: 0

Views: 92

Answers (2)

Sylwit
Sylwit

Reputation: 1577

You are looking for HAVING

SELECT member_code, sum(product_price) as totalSales FROM src_calculation_daily GROUP BY member_code HAVING totalSales > 100

WHERE is used when the fields exists in your table

HAVING is used on a calculated value

Upvotes: 1

Gordon Linoff
Gordon Linoff

Reputation: 1269873

I think you just want a HAVING clause:

SELECT member_code, sum(product_price) as totalSales
FROM src_calculation_daily
GROUP BY member_code
HAVING totalSales > 100;

Upvotes: 3

Related Questions