Reputation: 11
Please help, I run query :
SELECT *
FROM `euclidean`
WHERE id_latihan = '46'
ORDER BY jarak ASC
LIMIT 3
Output :
I want to know how to count label from that output, I want the output showing like this :
+-------+---+
| LOBBY | 2 |
+-------+---+
| PMB | 1 |
+-------+---+
Any help will appreciate. Thanks in advance
Upvotes: 0
Views: 48
Reputation: 126
SELECT label, count(*)
FROM euclidean
WHERE id_latihan = '46'
GROUP BY label
ORDER BY label
LIMIT 3
Upvotes: 1
Reputation: 133400
assuming you want the resulting count from your select you could use
select label, count(*)
from (
SELECT *
FROM `euclidean`
WHERE id_latihan = '46'
ORDER BY jarak ASC
LIMIT 3) t
group by label
or directly form you query
SELECT label, count(*)
FROM `euclidean`
WHERE id_latihan = '46'
GROUP BY label
ORDER BY label
Upvotes: 0
Reputation: 684
Your question is similar to Join 3 tables with Count . Try this sql. This may be resolve your problem.
SELECT
p.label,
Count( t.id_latihan ) AS id_latihan
FROM
euclidean p
LEFT JOIN euclidean t ON p.id_latihan = t.id_latihan
where
p.id_latihan = 46
GROUP BY
p.label
Upvotes: 0