Choosing Mysql with Conditional Logic

I need help with the following:
(my description may seem strange, example below)

in order to generate a graph, I want to select the "days" based on the request generated by the form (at this stage the request will contain only the countries "from" and "to").

My problem is that I have no idea how to choose to use conditional logic, so it selects โ€œdaysโ€ from each โ€œitem_idโ€ that has a โ€œfromโ€ and โ€œtoโ€ match.

(well, another problem is that I donโ€™t know any good keywords or actually what it is called, so please forgive me, I just did a few blind searches and tried to find similar problems here)

example

0
1
SELECT days.meta_value
FROM tableName AS from_country,
     tableName AS to_country,
     tableName AS days
WHERE from_country.item_id = to_country.item_id
  AND from_country.item_id = days.item_id
  AND from_country.field_id = 90
  AND to_country.field_id = 93
  AND days.field_id = 251

, from_country.meta_value . tableName .

from_country, to_country days , , , . , , , , . .

, , :

CREATE VIEW viewName AS
SELECT item.item_id AS item_id,
       from_country.meta_value AS from_country,
       to_country.meta_value AS to_country,
       days.meta_value AS days
FROM (SELECT DISTINCT item_id FROM tableName) AS item
     LEFT JOIN tableName AS from_country
            ON (from_country.item_id = item.item_id AND
                from_country.field_id = 90)
     LEFT JOIN tableName AS to_country
            ON (to_country.item_id = item.item_id AND
                to_country.field_id = 93)
     LEFT JOIN tableName AS days
            ON (days.item_id = item.item_id AND
                days.field_id = 251)

, :

SELECT days FROM viewName WHERE from_country LIKE 'A%'

, . , - NULL. , , . , .

+2

All Articles