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

mysql语句应该怎么组合

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:21:20
Original
1175 people have browsed it

mysql语句应该怎么组合

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

这是我想要的效果。谢谢

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

</code>
Copy after login
Copy after login

回复内容:

mysql语句应该怎么组合

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

这是我想要的效果。谢谢

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

</code>
Copy after login
Copy after login

<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>
Copy after login
Related labels:
Statement of this Website
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
Latest Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template