p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   SQL Language (http://p2p.wrox.com/forumdisplay.php?f=100)
-   -   new display count query (http://p2p.wrox.com/showthread.php?t=57295)

carswelljr April 30th, 2007 11:49 AM

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


gbianchi April 30th, 2007 11:53 AM

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
================================================== =========

carswelljr April 30th, 2007 12:14 PM

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




gbianchi April 30th, 2007 12:24 PM

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
================================================== =========

dparsons April 30th, 2007 12:33 PM

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
================================================== =========

carswelljr April 30th, 2007 12:41 PM

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?


gbianchi April 30th, 2007 12:54 PM

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
================================================== =========

carswelljr April 30th, 2007 01:18 PM

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!!!


gbianchi April 30th, 2007 01:22 PM

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
================================================== =========

carswelljr May 7th, 2007 04:59 PM

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




All times are GMT -4. The time now is 02:33 PM.

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