2

表结构:

CREATE TABLE `blogs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `blog` text,
  `status` enum('published','draft','trash') DEFAULT NULL,
  PRIMARY KEY (`id`)
)

希望查询显示结果如下:

published   draft    trash
-----------------------------
   3          5         1 
-----------------------------
4

1 回答 1

2
select sum(status = 'published') as published,
       sum(status = 'draft') as draft,
       sum(status = 'trash') as trash
from blogs
于 2013-10-28T07:27:47.777 回答