每日一句 ( 2025115 )  

Problems are not stop signs; they are guidelines.

問(wèn)題的出現(xiàn)不是讓你止步,而是給你指路。———— Robert Schuller

mysql中sum()函數(shù)結(jié)合case when及groupby

今天在做一個(gè)銷售業(yè)績(jī)的排行功能,統(tǒng)計(jì)公司銷售在本月及當(dāng)天的業(yè)績(jī)金額并進(jìn)行排行。 例:數(shù)據(jù)表中有以下幾個(gè)關(guān)鍵字段:用戶名username,金額P,簽單時(shí)間T ….銷售每簽一單就錄入一條記錄。 SQL語(yǔ)句: $today = strtotime(“today”); ? ?//今天零點(diǎn)時(shí)間戳 SELECT *,SUM(P) AS total_P_month,SUM(CASE WHEN T>$today THEN P ELSE 0 END) AS total_P_today FROM table WHERE T&g...