0
SELECT sum( plot_status = 'OPEN' ) AS OPEN 
     , sum( plot_status = 'SOLD' ) AS SOLD
FROM `tbl_plot`
GROUP BY `plot_status

This is giving

OPEN   SOLD
7       0
0       8

How to make it

OPEN  SOLD
7      8

Or is it possible?

0

3 Answers 3

2

just remove the GROUP BY clause and it will work.

SELECT sum( plot_status = 'OPEN' ) AS `OPEN` ,
       sum( plot_status = 'SOLD' ) AS SOLD
FROM  `tbl_plot`
Sign up to request clarification or add additional context in comments.

Comments

1

If there is present plot_name or id then group by that not by plot_status:

SELECT sum( plot_status = 'OPEN' ) AS
OPEN , sum( plot_status = 'SOLD' ) AS SOLD
FROM `tbl_plot`
GROUP BY //`plot_name or plot_id

This will work for you for individual plot. And if you don't want that then remove the group by clause.

Comments

1

select * from ( select sum( plot_status = 'OPEN' FROM tbl_plot ) AS OPEN select sum( plot_status = 'SOLD' FROM tbl_plot ) As Sold )tbl

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.