V
V
Vincent2018-05-15 10:46:56
MySQL
Vincent, 2018-05-15 10:46:56

How to get all data?

Hi everybody!
There is a table:
post (id, name, text, status, sum1, sum2)
I make such a request to calculate the sums of sum1 and sum2. I get the sum_all column and build a query on it.

select *, (sum1 + sum2) AS sum_all from `post` having `sum1` >= 0 and `sum2` <= 90 order by `id` desc

How do I apply where status = 1 here?
I try to do like this:
select *, (sum1 + sum2) AS sum_all from `post` where `status` = 1 having `sum1` >= 0 and `sum2` <= 90 order by `id` desc

But it does not display all records that have status 1, but only those that have the same sum_all. Tell me how to do it right?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Boris Korobkov, 2018-05-15
@BorisKorobkov

move from having to where

I
iljaGolubev, 2018-05-15
@iljaGolubev

where `status` = 1 AND `sum1` >= 0 and `sum2` <= 90

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question