Jump to content

Query Help


TeddyIso

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/288682-query-help/
Share on other sites

 

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
Link to comment
https://forums.phpfreaks.com/topic/288682-query-help/#findComment-1480466
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/288682-query-help/#findComment-1480470
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.