General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 4th, 2012, 12:01 PM
meartech meartech is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 1 meartech User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 39 sec
Reputation Power: 0
Count total of a column in seperate table

I currently have a database with multiple tables which is the backend to a website. I currently draw a table to screen that lists various records in the table

SELECT Tickets.ID, Tickets.Title, Tickets.Priority, Tickets.Company, Tickets.Site, Tickets.Created, Tickets.[First Name], Tickets.[Last Name], Tickets.[Created By], Tickets.[Assigned to Queue], Tickets.[Assigned to User], Tickets.[Ticket Category], [Ticket - Status].Status FROM [Ticket - Status] INNER JOIN Tickets ON [Ticket - Status].ID = Tickets.[Ticket Status] WHERE (Tickets.Company = 1) AND (Tickets.[Ticket Status]<>5);

Sample output:

ID, Title, Status
1, PC not working, open
32, Test entry, open


I have another table called [Ticket - Notes] with the following entries

ID = AutoNumber
TIcket_ID = Number
UsedUnits = Number

Typical data would be

ID, Ticket_ID, UsedUnits
14, 1, 1
15, 32, 1
16, 32, 3

I need to adjust my top SQL query to count the total of Used Units for each row

This would change my first Sample output to
ID, Title, Status, UnitsUsed
1, PC not working, open, 1
32, Test entry, open, 4

Can anyone help!

Reply With Quote
  #2  
Old July 10th, 2012, 06:38 PM
bitsmed bitsmed is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 11 bitsmed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 59 m 53 sec
Reputation Power: 0
Code:
select a.id
      ,a.title
      ,b.status
      ,sum(usedunits) as usedunits
  from ticket as a
       inner join [ticket - status] as b
               on b.id=a.[ticket status]
       inner join [ticket - notes] as c
               on c.ticket_id=a.id
 where a.company=1
   and a.[ticket status]<>5
 group by a.id
         ,a.title
         ,b.status

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > Count total of a column in seperate table


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap