Advertisement

10.16.2004 at 10:33PM PDT, ID: 21171312
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.6

Trying to optimize multiple queries into a single query

Asked by NeonDevil in MySQL Server

Tags: , , , ,

I've tried several different methods, but can't quite get the information I need in a single query.

The main hurdle to get over is that I need to return these rows (all 16 of them) no matter what, even if the result is NULL/blank, and have them in a specific order.

I've tried to sort the results in a specific order, turning rows into columns (which the following query does - but not efficiently), and using different variations of IF/WHEN statements.

Doing an ORDER BY doesn't quite work for my needs because if their COUNT is null, it doesn't show in the resultset.
Is there a way to 'force' results into rows? If so, then that method would work perfectly [i.e. if COUNT(crd_class) for 'Ar' is NULL, then result='0', else COUNT(crd_class) ] - I can't figure out the syntax.
Is there a specific mySQL function that will convert rows into columns?

Anyway, here's the query I'm using

SELECT
(SELECT COUNT(crd_class) FROM credits WHERE crd_class='Ar' GROUP by crd_class) Ar,
(SELECT COUNT(crd_class) FROM credits WHERE crd_class='As' GROUP by crd_class) As,
(SELECT COUNT(crd_class) FROM credits WHERE crd_class='Mk' GROUP by crd_class) Mk,
(SELECT COUNT(crd_class) FROM credits WHERE crd_class='Sc' GROUP by crd_class) Sc,
(SELECT COUNT(crd_class) FROM credits WHERE crd_class='Wa' GROUP by crd_class) Wa,
(SELECT COUNT(crd_class) FROM credits WHERE crd_class='Bd' GROUP by crd_class) Bd,
(SELECT COUNT(crd_class) FROM credits WHERE crd_class='Dr' GROUP by crd_class) Dr,
(SELECT COUNT(crd_class) FROM credits WHERE crd_class='He' GROUP by crd_class) He,
(SELECT COUNT(crd_class) FROM credits WHERE crd_class='Wi' GROUP by crd_class) Wi,
(SELECT COUNT(crd_class) FROM credits WHERE crd_class='Ap' GROUP by crd_class) Ap,
(SELECT COUNT(crd_class) FROM credits WHERE crd_class='Pa' GROUP by crd_class) Pa,  
(SELECT COUNT(crd_class) FROM credits WHERE crd_class='Sp' GROUP by crd_class) Sp,
(SELECT COUNT(crd_class) FROM credits WHERE crd_class='Co' GROUP by crd_class) Co,
(SELECT COUNT(crd_class) FROM credits WHERE crd_class='Re' GROUP by crd_class) Re,
(SELECT COUNT(crd_class) FROM credits WHERE crd_class='Pe' GROUP by crd_class) Pe,
(SELECT COUNT(crd_class) FROM credits WHERE crd_class='Ra' GROUP by crd_class) Ra
FROM credits WHERE mem_id='1' GROUP BY mem_idStart Free Trial
 
Loading Advertisement...
 
[+][-]10.18.2004 at 12:00AM PDT, ID: 12336603

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.18.2004 at 06:15AM PDT, ID: 12337983

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.18.2004 at 08:59AM PDT, ID: 12339269

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.18.2004 at 05:00PM PDT, ID: 12343271

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.18.2004 at 10:03PM PDT, ID: 12344695

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.18.2004 at 10:58PM PDT, ID: 12344885

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MySQL Server
Tags: mysql, multiple, optimize, query, rows
Sign Up Now!
Solution Provided By: JakobA
Participating Experts: 1
Solution Grade: B
 
 
[+][-]04.05.2005 at 11:25AM PDT, ID: 13710101

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 14-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]04.12.2005 at 07:17AM PDT, ID: 13762449

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 14-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-43