Jump to content

Query Help


Go to solution Solved by Psycho,

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?

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

  • Solution

 

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.