old Mysql query problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • T.A.C. One

    #1

    old Mysql query problem

    I'd like to get the following query workin with Mysql 3.x.

    "customers" table
    id name email
    =============== =============== ====
    1 John john@email.com
    2 Marvin mrv@yahoo.com
    ....

    "orders" table

    id customer_id price
    =============== ==============
    1 1 5.00
    2 2 10.00
    1 1 7.00
    ....


    Here's the query

    Select * FROM customers a INNER JOIN
    (SELECT COUNT(id) as numOrders, SUM(price) as totprice, customer_id FROM
    orders GROUP BY customer_id) b ON a.id=b.customer _id).

    How should I rewrite the query to get it working on mysql 3?

    Id like to get this result

    id name email numOrders totprice
    =============== =============== ===========
    .... ... .. ... ...

    Any suggestion?

    Tac
  • Aggro

    #2
    Re: old Mysql query problem

    T.A.C. One wrote:
    [color=blue]
    > Any suggestion?[/color]

    Perhaps something like this: (just fix table names and column names if I
    got them wrong)

    select customer.id,nam e,email,count(* ) as num,sum(price) as total_price
    from orders,customer where orders.customer _id=customer.id group by
    customer_id;

    Comment

    • Aggro

      #3
      Re: old Mysql query problem

      T.A.C. One wrote:
      [color=blue]
      > Any suggestion?[/color]

      Perhaps something like this: (just fix table names and column names if I
      got them wrong)

      select customer.id,nam e,email,count(* ) as num,sum(price) as total_price
      from orders,customer where orders.customer _id=customer.id group by
      customer_id;

      Comment

      • Aggro

        #4
        Re: old Mysql query problem

        T.A.C. One wrote:
        [color=blue]
        > Any suggestion?[/color]

        Perhaps something like this: (just fix table names and column names if I
        got them wrong)

        select customer.id,nam e,email,count(* ) as num,sum(price) as total_price
        from orders,customer where orders.customer _id=customer.id group by
        customer_id;

        Comment

        Working...