TeddyIso Posted May 22, 2014 Share Posted May 22, 2014 (edited) Situation: I have a table that I fill with various types of bugs. Each bug in the table will have an id, name(of a program/script), the bug information, and a resolved column (0 or 1). What I need to be able to do is query the number of bugs that each program has but also query it for each script/program. I have tried: SELECT `name`, COUNT(`bug`) AS `bugs` FROM `bugs` but that returns only one row being the first script/program name and the count of all bugs for all scripts/programs. Could someone please advise me where I'm going wrong? Edited May 22, 2014 by TeddyIso Quote Link to comment Share on other sites More sharing options...
Solution Psycho Posted May 22, 2014 Solution Share Posted May 22, 2014 What I need to be able to do is query the number of bugs that each program has but also query it for each script/program. Huh? Per your table you have only one column to store 'name(of a program/script)'. I don't see how you can get information for scripts within a program. Or maybe you are just not describing it accurately. Plus, your query is doing a count of a field called 'bug' which doesn't exist based on your description. If you just want count by unique values in the 'name' column, use this: SELECT name, COUNT(id) AS bug_count FROM bugs GROUP BY name Quote Link to comment Share on other sites More sharing options...
TeddyIso Posted May 22, 2014 Author Share Posted May 22, 2014 (edited) Sorry, the name will be the same for some rows. It's an identifier for the bug itself. The name will contain something like IP Board, PhpBB, etc. Each bug will fall under the name. For example, I could add something like id: 1 - name: IP Board - bug: Something wrong - resolved: 0 id: 2 - name: IP Board - bug: Something else wrong - resolved: 0 id: 3 - name: PhpBB - bug: Everything - resolved: 0 What I would like to do is add up all the `bug` from the columns with the same `name` as one returned value. Edit: Tweaked your query a bit and now it works perfectly, thank you very much Edited May 22, 2014 by TeddyIso Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.