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:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old November 15th, 2005, 08:22 PM
kim123 kim123 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 3 kim123 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 47 m 22 sec
Reputation Power: 0
Complex query?

I need some help with a query I'm writing

I got four tables with the fields:
Code:
Request (id, req_num, timestap, desc, userid)
Change (id, req_id, chg_num, timestamp, update_text) 
Change_hist (id, chg_id, timestamp, action, comment)
User(userid, fname, lname)



A user log a request which most likely is split up into several work parts (change) and then for each update of the change its stored in the change_hist table.

The change_hist table has a action field which is used to track changes. Each change should go from 'open -> assigned' and then to 'assigned -> responded'. This is the important thing in this query...

What I'm trying to do is:
List out all users that has a request logged,
List total requests the user has logged
List total requests the user has logged that has been through the correct status change.

So I got the query:

Code:
select distinct 
    lname,
    count(request.id)
from request
    right join change on request.id = change.req_id
    left join user on request.userid = user.userid


This gives me the correct total requests logged by each user, but when I add the change_hist field it messes it all up...

Any ideas about this?

Reply With Quote
  #2  
Old November 16th, 2005, 04:29 AM
kim123 kim123 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 3 kim123 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 47 m 22 sec
Reputation Power: 0
Maybe I haven't really explained well what I'm trying to do...
the fields I need are:

lname,
count(request.id) AS [Total Requests],
count(request.id) AS [Correct Requests]

the two first columns are ok, but the third one is my issue.
I need to count all requests where the change_hist.action has entry = open -> assigned' AND 'assigned -> responded'

Still not able to get this right and need any advice at this stage

Reply With Quote
  #3  
Old November 17th, 2005, 04:16 PM
kim123 kim123 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 3 kim123 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 47 m 22 sec
Reputation Power: 0
Forget it...got a helping hand and was able to create a solution.

This gotta be the slowest forum around...geez

Reply With Quote
  #4  
Old November 21st, 2005, 12:46 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
Please endulge us on your solution.
Might as well help others with the same issue.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > Complex query?


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway