count(case when (reqtype='login' or reqtype='register') thenimei end)是計(jì)數(shù)reqtype='login' 和reqtype='register'的數(shù)量;
COUNT(distinct imei), 是當(dāng)reqtype='login' 和reqtype='register'時(shí)去重計(jì)數(shù)imei的數(shù)量.那我怎么寫才能實(shí)現(xiàn)統(tǒng)計(jì)reqtype的值是login或者register的count(imei)值呢count(case when (reqtype='login' or reqtype='register') thenimei end)我這樣查出來的只是reqtype='login' 的count值就這點(diǎn)不明白count是計(jì)數(shù),如果是:""實(shí)現(xiàn)統(tǒng)計(jì)reqtype的值是login或者register的count(imei)值"",也就是說當(dāng)實(shí)現(xiàn)統(tǒng)計(jì)reqtype的值是login或者register有多少個(gè) IMEI;此時(shí)與IMEI值本身有任何關(guān)系.可以使用:sum(case when reqtype in ('login','register') then 1 else 0 end)如果你是統(tǒng)計(jì)reqtype的值是login或者register時(shí)IMEI的值,此時(shí)與IMEI值有關(guān),可以使用:sum(case when reqtype in ('login','register') then imei else 0 end)就行啦.
sql語(yǔ)句 case when or
sql語(yǔ)句 case when or
自己寫的sql
select date_format(createDate,'%Y-%m-%d') as createDate,
count(case when reqtype='runUp' then imei end) as runUp,
count(case when (reqtype='login' or reqtype='register') then imei end) as login
FROM (select distinct imei,date_format(createDate,'%Y-%m-%d') as createDate,reqtype
from stat_user_loginreq_201312 where 1=1 and DATE_FORMAT(createDate,'%Y-%m-%d') = '2013-12-01'
) AS g group by DATE_FORMAT(createDate,'%Y-%m-%d') order by createDate
查出來的count(case when (reqtype='login' or reqtype='register') then imei end)的值和
select COUNT(distinct imei),date_format(createDate,'%Y-%m-%d') from stat_user_loginreq_201312 where 1=1
and (reqtype='login' or reqtype='register')
and DATE_FORMAT(createDate,'%Y-%m-%d') = '2013-12-01'
group by DATE_FORMAT(createDate,'%Y-%m-%d') order by createDate
查出來的不一樣
自己寫的sql
select date_format(createDate,'%Y-%m-%d') as createDate,
count(case when reqtype='runUp' then imei end) as runUp,
count(case when (reqtype='login' or reqtype='register') then imei end) as login
FROM (select distinct imei,date_format(createDate,'%Y-%m-%d') as createDate,reqtype
from stat_user_loginreq_201312 where 1=1 and DATE_FORMAT(createDate,'%Y-%m-%d') = '2013-12-01'
) AS g group by DATE_FORMAT(createDate,'%Y-%m-%d') order by createDate
查出來的count(case when (reqtype='login' or reqtype='register') then imei end)的值和
select COUNT(distinct imei),date_format(createDate,'%Y-%m-%d') from stat_user_loginreq_201312 where 1=1
and (reqtype='login' or reqtype='register')
and DATE_FORMAT(createDate,'%Y-%m-%d') = '2013-12-01'
group by DATE_FORMAT(createDate,'%Y-%m-%d') order by createDate
查出來的不一樣
其他人氣:864 ℃時(shí)間:2020-07-04 03:21:31
優(yōu)質(zhì)解答
我來回答
類似推薦
- SQL語(yǔ)句case when
- 以下成語(yǔ)與哪個(gè)歷史人物有關(guān).草船借箭 完璧歸趙 臥薪嘗膽
- 三角梅的特點(diǎn)
- 故宮太和殿內(nèi)那塊牌匾上的四個(gè)字是什么?
- 求高手幫忙寫一篇英文信
- (1)某商店將某種DVD按進(jìn)價(jià)提高40%定價(jià),促銷后,每臺(tái)仍獲利2元.每臺(tái)DVD的進(jìn)價(jià)是多少元?
- People like to eat watermelon in hot summer.
- 對(duì)我來說編英語(yǔ)對(duì)話不難 It ____ difficult ____ me ____ ____ ____ English dialogues
- 煤礦安全規(guī)程由多少條
- He doesn't walk_______the park.He goes _______bike.括號(hào)里填什么?A:to.on B:on.by C:to.by
- 半徑為6cm的扇形的弧長(zhǎng)為6.28cm,求這個(gè)扇形的面積
- 與常染色體隱性遺傳相比,X染色體上的隱性遺傳的特點(diǎn)是( ?。?A.男性患者多于女性患者 B.女性患者多于男性患者 C.只有男性發(fā)病 D.男女發(fā)病率相同
猜你喜歡
- 1“人體內(nèi)的細(xì)胞外液主要包括血漿,組織液和淋巴”這句話為什么不對(duì)
- 2y=-2x+b的圖像與兩坐標(biāo)軸圍城的三角形面積為3.(1)求這個(gè)函數(shù)的解析式(2)求原點(diǎn)到這個(gè)圖像的距離
- 34的n次方·a的2n次方·b的3n次方=( )的n次方.
- 4—What do you think made Mary soupset?_____her new bike.A.As she lo.com
- 5若X的二次方+3X+1=0,則X的三次方+5X的二次方+5X+8=?
- 6計(jì)算:5x-2y-6+ (1/x) + (1/y)
- 7英語(yǔ)翻譯
- 81,2題 有圖
- 9下列有關(guān)長(zhǎng)江中下游平原敘述正確的
- 10糖吃多了會(huì)怎樣,哪些食物糖類高
- 11排列與組合題,這樣有什么不對(duì)?
- 124/5x-x=120