简体   繁体   中英

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

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;

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM