mysql query: SELECT DISTINCT column1, GROUP BY column2

后端 未结 5 632
后悔当初
后悔当初 2020-12-30 02:02

Right now I have the following query:

SELECT name, COUNT(name), time, price, ip, SUM(price) 
  FROM tablename 
 WHERE time >= $yesterday 
   AND time <         


        
5条回答
  •  鱼传尺愫
    2020-12-30 02:40

    Somehow your requirement sounds a bit contradictory ..

    group by name (which is basically a distinct on name plus readiness to aggregate) and then a distinct on IP

    What do you think should happen if two people (names) worked from the same IP within the time period specified?


    Did you try this?

    SELECT name, COUNT(name), time, price, ip, SUM(price) 
      FROM tablename 
     WHERE time >= $yesterday AND time <$today 
    GROUP BY name,ip
    

提交回复
热议问题