每日一句 ( 2024920 )  

Years may wrinkle the skin, but to give up enthusiasm wrinkles the soul.

歲月留痕,只及肌膚;激情不再,皺起心靈。———— Samuel Ullman

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

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