`
dannyhz
  • 浏览: 371725 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

mysql count 各种情况 case when

 
阅读更多


select a.num  , a.success  , a.num - a.success as fail
from 
(
SELECT   
count(1) AS num,  
count(case when detail_voucher_id is not null then detail_voucher_id end ) AS success
FROM fm_account_recharge 
where date_format(pay_finish_time, '%Y-%m-%d') = date_format('2018-02-24','%Y-%m-%d') 
and recharge_mode = 1 
) a

分享到:
评论

相关推荐

    case when和sum case when 写法及拼接字段

    1 case when 写法 2 sum case when 用法 3 select 拼接字段 示例如下: when 2 then 'C' else 'D' end ) as '类型',count(*) as '数量' from table group by orderType

    mysql数据库的基本操作语法

    MySQL结束符是“;”结束。 1、 显示所有数据库 show databases; 2、 删除数据库 drop database dbName; 3、 创建数据库 create database [if not exists] dbName; 中括号部分可选的,判断该数据不存在就创建 4、 ...

    MyDAC7.6.11

    Performance of backing up process using TMyDump in case when TableNames is specified is improved Bug with data loss in pessimistic lock mode is fixed Bug with AV failure in RefreshQuick method is ...

    两种方法实现mysql分组计数,范围汇总

    SUM(ddd) AS count_days, CASE WHEN aa.days >= 1 AND aa.days < 3>= 3 AND aa.days < 5 THEN '5-3' ELSE '5+' END AS groupby_days FROM ( SELECT SUM(1) AS ddd, days FROM tour_group GROUP BY ...

    Sql for mysql

    CHAPTER 1 Introduction to MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.2 Database, ...

    sql多表行转列、级联行转列示例代码

    现有两表A,B A表存储商品点击日志,B表存储商品 ...as 总数’ select @sql =@sql+ ‘,sum(case b.title when ”’+Title+”’ then 1 else 0 end) as ‘+'[‘+Title+’]’ from (select distinct title from B) as B

    php.ini-development

    Directive names are *case sensitive* - foo=bar is different from FOO=bar. ; Directives are variables used to configure PHP or PHP extensions. ; There is no name validation. If ...

    经典全面的SQL语句大全

    select type,sum(case vender when 'A' then pcs else 0 end),sum(case vender when 'C' then pcs else 0 end),sum(case vender when 'B' then pcs else 0 end) FROM tablename group by type  显示结果: type ...

    oracle学习文档 笔记 全面 深刻 详细 通俗易懂 doc word格式 清晰 连接字符串

    Mysql 甲骨文 是个开源的数据库server,可运行在多种平台, 特点是响应速度特别快,主要面向中小企业 中小型企业 PostgreSQL 号称“世界上最先进的开源数据库“,可以运行在多种平台下,是tb级数据库,而且性能也很...

    SQL培训第一期

    1.8.2 case when 1.8.2.1 语法 select t.uuid, t.score, case when t.score > 90 then '优秀' when t.score > 60 then '及格' else '不及格' end from exam_user_exam t 1.8.3 decode 1.8.3.1 语法 select ...

Global site tag (gtag.js) - Google Analytics