Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
| Search | Today's Posts | Mark Forums Read
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old April 30th, 2007, 11:49 AM
Authorized User
 
Join Date: Aug 2006
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default new display count query

SELECT v.category, COUNT(v.category) AS issue_count, c.color
FROM TICKET_VIEW v, COLORTBL c
WHERE (c.min_issues > issue_count) AND (c.max_issues <= issue_count)
GROUP BY v.category
ORDER BY v.category


i keep getting these errors:
"you tried to execute a query that does not include the specified expression 'color' as part of an aggregate function."
or
"no value given for one or more parameters."

can someone tell what i am dong wrong and why this query will not execute?
thank you

  #2 (permalink)  
Old April 30th, 2007, 11:53 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

well.. c.color is not part of an aggregate function... what do you expect to receive from this query???

also be aware that that query do a full join bettween the two tables.. (b/c there is no relation between v and c)...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
  #3 (permalink)  
Old April 30th, 2007, 12:14 PM
Authorized User
 
Join Date: Aug 2006
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I would like to count 5 categories, which will be based on the group_name that has the most values. (eg group_name1 was chosen 10 times, group_name2 was chosen 3 times all for category1, then the image in the cell next to category 1 should be red, because errorcode1 contained the most values for that category.

eg of how the webpage looks:
(5 categories, 5 group_names, 3 images for colorcode)

Ticket_view
Category 1 --> group_name1(10) red
Category 2 --> group_name2 (6) yellow
Category 3 --> group_name3 (5) yellow
Category 4 --> group_name4 (3) green
Category 5 --> group_name5 (1) green

Colortbl.dbo
color -------> green, yellow, red
min_issues --> 1, 3, 5
max_issues --> 3, 5, 999999999


legend:
green - 0-3 errors
yellow - 4-6 errors
red - 7+ errors



  #4 (permalink)  
Old April 30th, 2007, 12:24 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

just and idea (the syntax could be a little wrong, I'm writing this here)...

Code:
 SELECT c.color, s.cat, s.issue_count FROM
(SELECT     v.category, COUNT(v.category) AS issue_count
FROM         TICKET_VIEW v
GROUP BY v.category
ORDER BY v.category) s, COLORTBL c
WHERE     (c.min_issues > s.issue_count) AND (c.max_issues <= s.issue_count)
HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
  #5 (permalink)  
Old April 30th, 2007, 12:33 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Originally posted here:
http://p2p.wrox.com/topic.asp?TOPIC_ID=59303

and here as well
http://p2p.wrox.com/topic.asp?TOPIC_ID=59304

You never followed up with me in the source thread??

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
  #6 (permalink)  
Old April 30th, 2007, 12:41 PM
Authorized User
 
Join Date: Aug 2006
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank you for your help, it looks like i am getting closer, that query actually does execute but displays no results. what does the s in s.category, s.issue_count relate to?

  #7 (permalink)  
Old April 30th, 2007, 12:54 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

doug gives you a nice solution too.. why didn't you followed him up???

anyway the s are related to the inner select (the one in the from)... did that select return something???

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
  #8 (permalink)  
Old April 30th, 2007, 01:18 PM
Authorized User
 
Join Date: Aug 2006
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes, i got the query to return records. i used the solution doug provided me as well, but our dba did not want to use the case statements for some reason??? thank you both for all of your help!!!

  #9 (permalink)  
Old April 30th, 2007, 01:22 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

you could just tell doug that and eventually we would find another way to do it... you didn't need to start a new thread... and glad you make it work...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
  #10 (permalink)  
Old May 7th, 2007, 04:59 PM
Authorized User
 
Join Date: Aug 2006
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

o.k this one query is driving me nuts. i got records to display but not the way i need them to. one of my buddies said that i cannot write this query with 1 statement that it has to be in 2 and loop. i got the 1st part to return records, count the records, but i cannot get it to count the issues and associate it with a color from the colortbl. help please

1). SELECT v.category, COUNT(v.category) AS issue_count
FROM TICKET_VIEW v
GROUP BY v.category
ORDER BY v.category

Then go through these results:

2) select color

from colortbl

where c.min_issues > $issue_count and c.max_issues <= $issue_count




Similar Threads
Thread Thread Starter Forum Replies Last Post
display count results and image in webpage carswelljr SQL Language 2 April 19th, 2007 09:44 AM
Display count of rows debjanib ASP.NET 1.0 and 1.1 Professional 7 May 5th, 2006 04:13 AM
query count? Raif Access 1 June 18th, 2004 05:08 PM
count clause in query mateenmohd SQL Server 2000 2 June 10th, 2004 01:47 AM
SQL query for count programmer_kay ADO.NET 1 April 18th, 2004 02:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.