如題,我在網(wǎng)上也找過(guò)相關(guān)解決方法,很多解答都是這么一句sql語(yǔ)句:
select?id,accountid,mark,max(createcount)?as?latest?from?accountmark?as?b?group?by?accountid?
使用maxcount。但是在我查出來(lái)的數(shù)據(jù)中似乎有些不對(duì),如圖,反白的那一條數(shù)據(jù),mark字段和createtime字段根本不對(duì)應(yīng)啊!
這是怎么回事?使用max函數(shù)后在count這樣靠譜嗎?
還有一條語(yǔ)句:select?*,count(accountid)?as?num?from?
(select?*?from?accountmark?order?by?createtime?desc)?`temp`??
group?by?accountid?order?by?createtime?desc?
這樣查出來(lái)的數(shù)據(jù)是對(duì)的
但是,我需要?jiǎng)?chuàng)建count,count中視圖里不允許出現(xiàn)count子句。求大神些一條sql語(yǔ)句,能實(shí)現(xiàn)既不出現(xiàn)子句,又能查出正確數(shù)據(jù)。謝謝!
?
解決方法:
select?*?from?AccountMark?as?b?where?not?exists(select?1?from?AccountMark?where?AccountId=?b.AccountId
and?b.CreateTime
?