每日一句 ( 20241222 )  

Rivers know this: there is no hurry. We shall get there some day.

河流知道這一點(diǎn):無需匆忙。我們終有一日會到達(dá)。———— A. A. Milne

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

今天在做一個(gè)銷售業(yè)績的排行功能,統(tǒng)計(jì)公司銷售在本月及當(dāng)天的業(yè)績金額并進(jìn)行排行。例:數(shù)據(jù)表中有以下幾個(gè)關(guān)鍵字段:用戶名username,金額P,簽單時(shí)間T ….銷售每簽一單就錄入一條記錄。SQL語句:$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...