how to sum of a column with different values

amandeep :

I have a MySQL table which contains val_type column which have 3 type of values

 id     val_type   company
 1       rib         1
 2       mod         2
 3       rib         2
 4       rib         3
 5       mod         1
 6       trop        1

 $res= SELECT SUM(val_type) from tabl_name GROUP BY company;
 with above query I get sum of all types in one

  Result Required : Rib=3, mod=2 and trop=1

I want to get sum of all three types with one MySQL query. like how many rib,mod and trop.

Thanks

Tim Biegeleisen :

It sounds like you want to count all three types. You only need a basic GROUP BY query:

SELECT
    val_type,
    COUNT(*) AS cnt
FROM tabl_name
GROUP BY
    val_type;

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=379432&siteId=1