0
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

或者有可能吗?

4

3 回答 3

2

只需删除该GROUP BY子句,它就会起作用。

SELECT sum( plot_status = 'OPEN' ) AS `OPEN` ,
       sum( plot_status = 'SOLD' ) AS SOLD
FROM  `tbl_plot`
于 2013-04-30T09:56:03.093 回答
1

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

于 2013-04-30T10:21:27.663 回答
1

如果存在 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 子句。

于 2013-04-30T09:58:30.203 回答