Sum amount by type of food in SQL Server -


i'm new sql, i'm using sql server 2008.

in database have 3 tables

  1. table type
  2. table invoice
  3. table item

this sql command sum amount:

select     tbl_type.type,    ((tbl_item.price * qty) - (tbl_item.price * qty * discount)) totalafter,    tbl_inv.dateinv     tbl_type, tbl_item, tbl_inv      tbl_inv.dateinv = '2013-03-26 00:00:00'     , tbl_inv.id = tbl_item.id_invoice     , tbl_type.id = tbl_item.id_type order     tbl_inv.dateinv; 

so when run query return

chicken        46.000000    2013-03-26 00:00:00.000 meat            3.000000    2013-03-26 00:00:00.000 chicken        69.000000    2013-03-26 00:00:00.000 chicken        46.000000    2013-03-26 00:00:00.000 chicken        69.000000    2013-03-26 00:00:00.000 meat            4.500000    2013-03-26 00:00:00.000 

but how this?

chicken       230.000000    2013-03-26 00:00:00.000 meat            7.500000    2013-03-26 00:00:00.000 

i error

column 'tbl_item.price' invalid in select list because not contained in either aggregate function or group clause.

when use group tbl_type.type in sql

thanks help.

select tbl_type.type,sum((tbl_item.price * qty) - (tbl_item.price * qty * discount)) totalafter ,tbl_inv.dateinv tbl_type,tbl_item,tbl_inv  tbl_inv.dateinv = '2013-03-26 00:00:00' , tbl_inv.id=tbl_item.id_invoice , tbl_type.id=tbl_item.id_type group tbl_type.type,tbl_inv.dateinv order tbl_inv.dateinv,tbl_type.type; 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -