Hi, in one of my projects, we store the data on trips of our customers in a table like this
id | user | country | travel_date | ------------------------------------------------------------------ 1 | 12 | 4 | 2012-03-13 16:57:41 | 1 | 17 | 8 | 2012-03-13 16:57:41 | 1 | 12 | 5 | 2011-03-13 16:57:41 | 1 | 13 | 8 | 2011-03-13 16:57:41 | 1 | 11 | 3 | 2011-03-13 16:57:41 | 1 | 10 | 1 | 2013-03-13 16:57:41 | 1 | 12 | 1 | 2012-03-13 16:57:41 |
And we have a country table like this
id | name ------+---------- 1 | India 2 | China 8 | Hongkong 3 | Singapore
Got a user table like this
id | Name --------+---------- 12 | name 17 | name 2 11 | name 3 10 | name 4
And we have to accept a report, for example
- Which customers traveled in China and India in 2012.
Request
SELECT DISTINCT user_id FROM traveled_details WHERE (country=1 OR country=2) AND YEAR(travel_date)=2012
We also got a customer table. All reports work fine.
But we have a new requirement that needs a report that clients have not traveled to China in 2012, or a List of clients traveling to the UN, ever, or clients who must travel in India.
Is my table structure sufficient to receive such a query? If yes, I am a little confused by this request ... Anyone please help?
source share