Advertisement

05.30.2008 at 05:41AM PDT, ID: 23444347
[x]
Attachment Details

Query to create summary / statistic from a table

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

8.4
Zone:

MySQL Server

Hi,

I need help to create a query for this situation.

I have this tables:

table_product
- product_model VARCHAR(10)
- description VARCHAR(200)

table_transaction
- distributor_code VARCHAR(10)
- product_model VARCHAR(10)
- status INT

I need a query to COUNT all the product_model for each distributor that has status=1

There are only 25 product_models btw.

So, the summary will look like this (see in the code snippet).

Basically it will list all the distributors and then count for each product_model if the status=1.

I am not sure if this can be done with single query? Or should I use temporary table? view?

Please help.

Thanks.

1:
2:
3:
4:
distributor product1 product2 product3 ... product25
 
ABC                0        1        0            50
CDEF               1       14        0            90
Answered By: Ray_Paseur
Expert Since: 02/08/2007
Accepted Solutions: 1015
Computer Expertise: Advanced
Ray_Paseur has been an Expert for 1 year 11 months, during which he has posted 4427 comments and answered 1015 questions. Ray_Paseur is just one of 2167 experts in the MySQL Server Zone. 2 experts collaborated on this answer, which was graded an "A" by the asker.
 
 
 
 
20081119-EE-VQP-47 / EE_QW_2_20070628