mysql distinct關鍵字在多個欄位的情況下出現行為怪異的問題

來源:互聯網
上載者:User

標籤:

我還是先把代碼貼上來吧

select be.ua , u.`name`, be.time_stamp, uvv.fans_count, uvv.friends_count, uvv.attetion_count, uvv.longitude, uvv.latitude,u.address_str, u.birthdate_stamp, u.emotion_role, u.personal_sign, u.personal_tags, u.constellation, u.logo_path, count(distinct be.ua) from laladb.bbs_events as be left join laladb.user as u on be.ua = u.uid left join laladb.user_variability_values as uvv on u.uid = uvv.uid where be.type = 1 and be.`status` = 1 and be.things_type = 0 and be.things_id = 1 group by be.ua order by be.time_stamp desc limit 0,2

 請注意count(distinct be.ua) 只有通過這種辦法才能夠讓distinct正常將重複的ua去掉,還要配合group by be.ua才會生效,否則結果集只有一行。

查詢到的結果會多一個名為count(distinct be.ua)的列,建議使用 as 關鍵字命名一個比較方便的比如dbu,然後在程式處理中將其unset掉。

 

coder-sunyuw

出處:http://www.cnblogs.com/sunyuw/p/4205681.html

註:歡迎轉載,但請保留作者和出處,謝謝

mysql distinct關鍵字在多個欄位的情況下出現行為怪異的問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.