我还是先把代码贴上来吧
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
注:欢迎转载,但请保留作者和出处,谢谢
时间: 2024-10-09 20:23:39