我有一个博客表。想要算作地位明智

时间:2013-10-28 07:25:22

标签: mysql

表格结构:

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 
-----------------------------

1 个答案:

答案 0 :(得分:2)

select sum(status = 'published') as published,
       sum(status = 'draft') as draft,
       sum(status = 'trash') as trash
from blogs