我還是先把代碼貼上來吧
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
注:歡迎轉載,但請保留作者和出處,謝謝