嗨我有以下查询:
SELECT PAS_User.user_user_id,
PAS_User.user_city,
PAS_User.user_company,
PAS_User.user_country,
PAS_User.user_account_type,
PAS_User.user_account_premium,
PAS_User.user_sign_up_date,
PAS_User.user_first_name,
PAS_User.user_last_name,
PAS_User.user_avatar_url,
PAS_User.user_cover_image_url,
PAS_User.user_bio,
PAS_User.user_sector,
PAS_User.user_job_type,
(SELECT COUNT(*) FROM `PAS_Follow` WHERE `folw_follower_user_id`=:sid) AS user_following_count,
(SELECT COUNT(*) FROM `PAS_Follow` WHERE `folw_followed_user_id`=:sid) AS user_followed_count,
(SELECT COUNT(*) FROM `PAS_Post` WHERE `post_user_id`=:sid) AS user_post_count,
(SELECT COUNT(*) FROM `PAS_Follow` WHERE `folw_follower_user_id`=:sid AND `folw_followed_user_id`=:cid) AS user_this_user_is_following,
(SELECT COUNT(*) FROM `PAS_Follow` WHERE `folw_followed_user_id`=:cid AND `folw_follower_user_id`=:sid) AS user_this_user_is_followed
FROM PAS_User
WHERE `PAS_User`.`user_user_id`=:sid
它旨在从其他表中获取个人资料页面的计数以及 :sid = 1 和 :cid = 2 的基本用户详细信息。
问题是,有没有更好的方法以更小的查询或更清洁的方式实现这一目标?
使用的表是
PAS_User , PAS_Follow & PAS_Post
谢谢
贾斯汀