douluo1330 2016-06-08 12:25
浏览 97
已采纳

php mysql数据库选择语句

Hey there I’m to sort out a php mysql message database with fields:

id, sms_text, receiver _number, time_sent, status.

I want to have a total count of that day (curdate) records of the number sms sent with number of successfully delivered and the number of failed. i.e. Total sms sent ____ , ______ delivered , ____failed

Howerver,

SELECT DATE(time_sent) AS date, SUM() AS total_sales 
  SELECT DATE(time_sent) AS date, SUM(status) AS total_sent from smsdb; 

does not seem to sort it out.

Kindly, any one help?

  • 写回答

1条回答 默认 最新

  • duancong7358 2016-06-08 12:29
    关注

    In MySQL boolean counts as 1(for true) and 0(for false) , so you can basically do this:

    SELECT DATE(time_sent) AS `date`,
           COUNT(*) as total_sent,
           SUM(status = 'succesfuly') as `delivered`,
           SUM(status = 'failed') AS `failed` 
    FROM smsdb
    GROUP BY DATE(time_sent) 
    

    I didn't know the status column options, change it from succesfuly,failed to the actual ones.

    I didn't understand what you were trying to do with your query, but you had a few problems there.

    SUM() -- you have to specify what to sum
    

    And you were missing a group by clause.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料