query problem

  • I have 2 database tables like Ordermaster and Orderdetails.

    In Ordermaster I have columns OrderId, OrderNo,SS_Name

    In Orderdetails I have columns OrderId, SS_Amount,SS_OrderBy

    The OrderId column is primary key in Ordermaster and a foreign key in Orderdetails

    Now I am trying to build a query which would give me a distinct list of all OrderId and OrderNo where the sum of SS_Amount for an orderid in Orderdetails = 100

    Any help...Thanks

  • select

    o.orderid

    , o.orderno

    , sum( ssamount)

    from ordermaster o

    inner join orderdetails od

    on o.orderid = od.orderid

    group by

    o.orderid

    , o.orderno

    having sum( od.ssamount) = 100

  • select o.orderid, o.orderno sum(od.ssamount)

    from orders o ,orderdetails od

    where o.orderid = od.orderid

    group by o.orderid, o.orderno

    having sum(od.quantity) = 100

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply