SQL Query Help :D

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Coolboy55
    New Member
    • Jul 2007
    • 67

    SQL Query Help :D

    I have a subquery with the following fields (among others) that are pulled from various tables: AssemblyName, PartName, UnitPrice, Quantity, and Cost. Cost is simply UnitPrice * Quantity. Each assembly has many parts, and each part has its own unit price and quantity.

    Now I am trying to make a new query that pulls the total part cost for each assembly. I have gotten the part cost sum successfully, but I'm not sure how to add the AssemblyName to the line with the sum, since I get the error "You tried to execute a query that does not include the specified expression "AssemblyNa me" as part of an aggregate function."

    Can anyone help? Sorry for the newb question! :) Thanks a lot!
  • Marknut
    New Member
    • Apr 2010
    • 42

    #2
    Code:
    Select assemblyname, sum( cost )
    From qry?
    Group by assemblyname

    Comment

    • Coolboy55
      New Member
      • Jul 2007
      • 67

      #3
      Oh wow, that was embarrassingly simple. :) Thanks a lot!

      Comment

      • Marknut
        New Member
        • Apr 2010
        • 42

        #4
        Hey man, we all start somewhere. The issue was that "group by" was missing in you query. Anytime you add aggregates, you need to group the fields that aren't aggregates. If you're using the query gui, right click and select "Totals." Then the "Totals" field appears and you can select things like Group By, Sum, Count...

        Comment

        Working...