Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Help Grouping By

Status
Not open for further replies.

civilwarjunky

IS-IT--Management
Aug 26, 2004
19
0
0
US
I am somewhat new to SQL and I am have a little trouble grouging items. My querry gives me the correct resualts other than I am not so fluent with grougping. Below is my code, and I need to group by item # ,and then total quantity of each item. Can you help ? Thanks

select customer.custid as 'Custid',customer.salut as 'Contact Type',custclass.classid as 'Calsss ID',custclass.descr as 'Class',
artran.refnbr as 'Invoice #',salesperson.Name as 'Marketing Code', Trandate as 'Order Date',customer.Attn,customer.name as 'Location',
customer.addr1 as 'Physical Address',customer.addr2 as 'Physical Address 2',customer.city as 'City',
customer.state as 'State',customer.zip as 'Zip',customer.Phone as 'Phone#',customer.fax as 'Fax', customer.emailaddr as 'E-mail',
customer.billaddr1 as 'Billing Addr',customer.billaddr2 as 'Billing Addr 2',customer.billcity as 'Bill City',
billstate as 'Bill state',customer.billzip as 'Bill Zip',artran.invtid as 'item #',inventory.descr as 'discription',artran.qty as 'Qty'
from artran,Inventory,Customer,Salesperson,custclass
where artran.invtid=Inventory.invtid
and artran.custid=customer.custid
and custclass.classid=customer.classid
and customer.billstate='ca'
and not customer.custid in ('calmkt','oosmkt,CALREP')-- These codes are for in house use
and trandate between '2004-07-01' and '2005-01-12'
and Salesperson.slsperid=*artran.slsperid
 
Sorry, but this is a bit confusing. You want to group by quantity? Or do you want a sum of quantities? Do you want this by customer as well? When you are grouping, every column that is not performing a group function MUST be in your GROUP BY clause, which can cause problems. For example, if you do not perform a group action on salesperson.Name and the name changes (such as a marriage), you will see multiple lines for what should be a single total. Also, you have items - such as Invoice - that you should either group by or remove from the list. Can you provide some additional information?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top