Home  >  Article  >  Backend Development  >  mysql语句应该怎么组合

mysql语句应该怎么组合

WBOY
WBOYOriginal
2016-06-06 20:21:201101browse

mysql语句应该怎么组合

我根据创建时间groupby能显示每个的总数量,但是做不了同时显示没使用的数量和使用的数量。
应该怎么写呢?

这是我想要的效果。谢谢

<code>券名字     类型  面额  没使用 使用
5000-100   1     100    2      1
1000       2     1000   1      1
10         3     10     1      0

</code>

回复内容:

mysql语句应该怎么组合

我根据创建时间groupby能显示每个的总数量,但是做不了同时显示没使用的数量和使用的数量。
应该怎么写呢?

这是我想要的效果。谢谢

<code>券名字     类型  面额  没使用 使用
5000-100   1     100    2      1
1000       2     1000   1      1
10         3     10     1      0

</code>

<code>select 
    name '券名字',
    type '类型',
    value '面额',
    sum(if(status=0,1,0)) '没使用',
    sum(if(status=1,1,0)) '使用' 
from 表名 
group by name order by type;</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn