2016-06-08 64 views
2

嘿,我整理出帶有字段一個PHP的MySQL數據庫信息:PHP MySQL數據庫select語句

id, sms_text, receiver _number, time_sent, status. 

我想有那一天(CURDATE)的總數人數短信發送記錄成功交付數量和失敗次數。 即共發送短信____,______交付,____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; 

似乎沒有整理出來。

請問有人幫忙嗎?

回答

1

在MySQL布爾計爲1(真正的)和0(假),所以你基本上可以做到這一點:

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) 

我不知道status列選項,它從succesfuly,failed改變實際的。

我不明白你想用你的查詢做什麼,但你有一些問題。

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

而你錯過了group by子句。

+1

實際上,從您的指導方針來看,它就像魅力一樣。謝謝。 –