sql command - help

  • Hi

    I have the folowing database in a table for example. im not sure how best to write the sql command

    What i want it to do is count the number of rows in the column 'bid' that correspond to the same session id (for example the below shows 4 rows all with 423400408 as the session id). Within also i than like to calculate each product by * quantity than adding them all together (making sure there all within the same session - 4 products (300*1) + (400 *5) + (600*4) + (150*2).

    Anyone please assist and i hope that explains it

     

    biditem_idquantitysession_idpricetime_stamp
    1231423400408300.0012/03/2005 8:45:54
    2255423400408400.0012/03/2005 8:45:54
    3214423400408600.0012/03/2005 8:45:54
    4132423400408150.0012/03/2005 8:45:54
    565423400501200.0012/03/2005 8:45:54

     

  • SELECT Bids.Session_ID, Count(Bids.Bid) AS CountOfBid, Sum([Price]*[Quantity]) AS PriceTimeQuantity

    FROM Bids

    GROUP BY Bids.Session_ID;

    Would that get what you're after?  Counts the bids by session id at the same time it calculates and sums price times quantity.

  • Thank you so much

    But why this statement

    Count(Bids.Bid) why count Bids.bid. Im confuded with 'bids' added

  • You wanted a count of how many bids were included in the same session_id.  that's teh count.  YOu can actually count any column that is guaranteed non-NULL.

  • i understand now. thank you once again

  • You're welcome.

Viewing 6 posts - 1 through 5 (of 5 total)

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