1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need help with query

Discussion in 'Databases' started by pepe_lepew1962, Apr 30, 2010.

  1. #1
    Hello:

    I am trying to get a mysql query together an not quite sure how to apply it, whether it is with distinct, join and all. What I am looking is to get the ID, qty ( number of users ), max and min number. Can anyone help me with this please.


    Name ID Name
    123ABC Engine
    649DFA Transmission
    854UDF Window


    User ID User Name User Amount
    123ABC Paul 300
    123ABC John 190
    649DFA Ian 500
    123ABC Mary 210
    123ABC Mark 225
    649DFA Steve 360




    Required Result:

    ID Qty Max Mix
    123ABC 4 300 190
    649DFA 2 500 360
     
    pepe_lepew1962, Apr 30, 2010 IP
  2. FriendSwapMeet.com

    FriendSwapMeet.com Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    are they all in the same column?
     
    FriendSwapMeet.com, Apr 30, 2010 IP
  3. pepe_lepew1962

    pepe_lepew1962 Member

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    No, the field names bunched together when I sent it.

    Name ID, Name


    User ID, User Name, User Amount
     
    pepe_lepew1962, Apr 30, 2010 IP
  4. FriendSwapMeet.com

    FriendSwapMeet.com Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    $result = mysql_query("SELECT * FROM ID");
    while($row = mysql_fetch_array($result))
    {
    $userid= $row['User ID'];
    $username = $row['User Name'];
    $User Amount = $row['User Amount'];
    }

    echo $userid . $username . $User Amount;


    try that code
     
    FriendSwapMeet.com, Apr 30, 2010 IP
  5. weaverIT

    weaverIT Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    We can do it in a single query..please check you PM
     
    weaverIT, May 7, 2010 IP
  6. danielbruzual

    danielbruzual Active Member

    Messages:
    906
    Likes Received:
    57
    Best Answers:
    0
    Trophy Points:
    70
    #6
    From your example it appears that you don't need the information on the first table. The solution is as simple as:

    SELECT B.user_id AS id, COUNT(B.user_name) AS Qty, Max(B.user_amount) AS Max, Min(B.user_amount) AS Min
    FROM B
    GROUP BY (id)
    ORDER BY id;

    Daniel
     
    danielbruzual, May 9, 2010 IP