I'm curious, is this result set can be achieved with sql query?
Here is the table
item_id name availability
-----------------------------------
1 brush available
2 brush available
3 paint not available
4 paint available
here is the result
name available not available
---------------------------------------
brush 2 0
paint 1 1
what could the query look like?
SELECT name,
COALESCE(SUM(CASE WHEN availability = 'available' THEN 1 ELSE 0 END), 0) AS available,
COALESCE(SUM(CASE WHEN availability = 'available' THEN 0 ELSE 1 END), 0) AS not_available
FROM mytable
GROUP BY
name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With