As @Rostan says, the four conditions that your query requires must be included as part of a WHERE
filter.
The query is very easy to put together. I'm going to put your conditions, and I'll be adding them one by one in the WHERE
part:
- first condition I want the id_gral to be equal to the one I send,
y
- second condition that is from a range of dates,
y
- third condition that the dst is equal to the one I send
y
- finally that from accountcode I get the last two digits and I want it to be equal to in.
We build the query:
SELECT *
FROM (falta indicar la forma en que se relacionan las tablas)
WHERE
g.id_gral=4 AND -- 1ª condición
c.calldate BETWEEN '2018-02-01%' AND '2018-10-25%' AND -- 2ª condición
c.dst = '175' AND -- 3ª condición
right(c.accountcode, 2) = 'in' -- 4ª condición
As you can see, the query remains in the air in the FROM
part, since you have one condition to define or rather, you need to contextualize the data design: how the tables are related .
Let's imagine a context: I have a table general
that is related to a table cuenta
using the column id_gral
.
With that context information, we can now complete the% share% of the query, and consequently the complete query:
SELECT *
FROM
general g INNER JOIN cuenta c ON g.id_gral=c.id_gral -- información que faltaba
WHERE
g.id_gral=4 AND -- 1ª condición
c.calldate BETWEEN '2018-02-01%' AND '2018-10-25%' AND -- 2ª condición
c.dst = '175' AND -- 3ª condición
right(c.accountcode, 2) = 'in' -- 4ª condición
By the way, I had never seen the use of FROM
in the conditions of %
. Is that good for something?