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

April 30th, 2007, 11:49 AM
|
|
Authorized User
|
|
Join Date: Aug 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

April 30th, 2007, 11:53 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
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
================================================== =========
|
|

April 30th, 2007, 12:14 PM
|
|
Authorized User
|
|
Join Date: Aug 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

April 30th, 2007, 12:24 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
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
================================================== =========
|
|

April 30th, 2007, 12:41 PM
|
|
Authorized User
|
|
Join Date: Aug 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|

April 30th, 2007, 12:54 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
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
================================================== =========
|
|

April 30th, 2007, 01:18 PM
|
|
Authorized User
|
|
Join Date: Aug 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!!!
|
|

April 30th, 2007, 01:22 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
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
================================================== =========
|
|

May 7th, 2007, 04:59 PM
|
|
Authorized User
|
|
Join Date: Aug 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|
 |