SELECT sum( plot_status = 'OPEN' ) AS OPEN
, sum( plot_status = 'SOLD' ) AS SOLD
FROM `tbl_plot`
GROUP BY `plot_status
这是给
OPEN SOLD
7 0
0 8
如何制作
OPEN SOLD
7 8
或者有可能吗?
只需删除该GROUP BY
子句,它就会起作用。
SELECT sum( plot_status = 'OPEN' ) AS `OPEN` ,
sum( plot_status = 'SOLD' ) AS SOLD
FROM `tbl_plot`
select * from (select sum(plot_status = 'OPEN' FROM tbl_plot
) AS OPEN select sum(plot_status = 'SOLD' FROM tbl_plot
) As Sold)tbl
如果存在 plot_name 或 id,则按其分组,而不是按 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
这将适用于您的个人情节。如果您不希望这样,请删除 group by 子句。