Mysql query average value

I'm having trouble creating a query that gives me an average. I read a few examples here on stackoverflow and couldn't do it. Can someone help me figure out how to do this, please? This is the data that I have:

Transaction_x0020_Number  Product_x0020_Code  Sales_x0020_Value  Date        Cashier
000356                    350                 24.99              2010-06-04  131    
000356                    726                 32.99              2010-06-04  131    
000357                    350                 24.99              2010-06-04  131    
000358                    350                 24.99              2010-06-04  131    
000358                    360                 24.99              2010-06-04  131    
000770                    703                 69.99              2010-06-04  130    
000771                    726                 32.99              2010-06-04  130    
000772                    1126                5                  2010-06-04  130    
000773                    482                 32.99              2010-06-04  130    
000774                    600                 32.99              2010-06-04  130    
000775                    350                 24.99              2010-06-04  130    

Basically, I need the average transaction cost of a cashier. I cannot run basic avg because it will accept all rows, but each transaction can have multiple rows. In the end I want to have:

Cashier| Average|  
131    | 44.31  |(Which comes from the sum divided by 3 transactions not 5 rows)  
130    | 33.15  |  
etc.  

This is a request that I have for SUM transactions, but I don’t know how and where to enable the AVG function.

SELECT `products`.`Transaction_x0020_Number`, 
       Sum(`products`.`Sales_x0020_Value`) AS `SUM of Sales_x0020_Value`, 
       `products`.`Cashier`   
  FROM `products`
GROUP BY `products`.`Transaction_x0020_Number`, `products`.`Date`, `products`.`Cashier`
  HAVING (`products`.`Date` ={d'2010-06-04'})  

Any help is appreciated.

+5
source share
2 answers
SELECT Cashier,
       Sum(Sales_x0020_Value) / COUNT(DISTINCT Transaction_x0020_Number) AS 'avg'
FROM products 
WHERE Date = {d'2010-06-04'}
GROUP BY Cashier
+14

, .

SELECT answers, AVG(score)
FROM tests
-3

All Articles