The schema of your contract should be like this:

Contract (id, level, ...)

where column 'id' is the primary key, isn't it?

If so, you can try this:

SELECT COUNT(id)
FROM contract 
GROUP BY level

----- Original Message ----- 
From: "Jay" <[EMAIL PROTECTED]>
To: <mysql@lists.mysql.com>
Sent: Thursday, May 11, 2006 5:41 PM
Subject: SELECT Query GROUP BY


> Hello MySQL Users
> 
> I have a contract table. Each contract has a certain level, which can be
> in a range from 1-5. This information is stored as a number. There is no
> additional table for the levels.
> 
> I would like to get a list with the amount of contracts of each level -
> including 0 for the levels with no contracts.
> 
> Until now I just used :
> SELECT COUNT(*), level FROM contract GROUP BY level
> but this is just showing level with contracts.
> 
> I tried a right join with a table which contains just integer values.
> Seems like a workaround, but I'm interested in a easier aolution - I bet
> there is one.
> 
> Thank you!
> 
> Jay
> 
> PS: I'm using Version 4.1
> 
> 
> -- 
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]
>

Reply via email to