sql - MySQL order results by total by weights -
i have following query:
select p.`id`, (select count(`id`) `comments` c c.`post_id` = p.`id`) `comments`, (select count(`id`) `likes` l l.`post_id` = p.`id`) `likes` `posts` p i want order results according third column, calculated following way:
order = comments * 6 + likes * 4 how can create "virtual" column , use results of other 2 in calculation?
thanks!
i rewrite query way:
select p.id, count(distinct comments.id) comments, count(distinct likes.id) likes, count(distinct comments.id)* 6 + count(distinct likes.id)* 4 `order` posts p left join comments on p.id = comments.post_id left join likes` on likes.`post_id` = p.`id` group p.id order `order`
Comments
Post a Comment