K
K
khodos_dmitry2020-01-02 12:55:45
SQL
khodos_dmitry, 2020-01-02 12:55:45

How to make that the subquery is not considered each time?

SELECT `id`, ROUND(`views`/(2020 - `releaseDate` + 1)*100/(SELECT ROUND(`views`/(2020 - `releaseDate` + 1)) pop FROM `manga` ORDER BY pop DESC LIMIT 1)) pop FROM `manga` WHERE `active` = 1 ORDER BY pop DESC LIMIT 10

How to make
(SELECT ROUND(`views`/(2020 - `releaseDate` + 1)) pop FROM `manga` ORDER BY pop DESC LIMIT 1)

not counted every time.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2020-01-02
@khodos_dmitry

SELECT `t`.`id`, ROUND(`t`.`views`/(2020 - `t`.`releaseDate` + 1)*100/`m`.`max`) AS `pop`
  FROM `manga` AS `t` 
  JOIN (
    SELECT MAX(ROUND(`views`/(2020 - `releaseDate` + 1))) AS `max`
      FROM `manga`
  ) AS `m`
  WHERE `t`.`active` = 1
  ORDER BY `pop` DESC
  LIMIT 10

L
Lazy @BojackHorseman, 2020-01-02
SQL

SELECT 
 t.`id`,
 <your_subquery> 
FROM (
SELECT *
FROM `manga` 
WHERE `active` = 1 
ORDER BY pop DESC LIMIT 10) t

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question