Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to select with some specific conditions but cannot seem to get what I am wanting.

Table Person person_id | first_name | last_name

Table Service service_id | person_id | start_time | end_time | service_type_id

Table Service_Types type_id | description

Table Service_User service_id | start_time | end_Time | user_id

The goal is to get all of the person_id's that meet any of the following criteria:

  1. Last Name Like 'Mar%'
  2. Service Type Like 'Fusions%'
  3. Service Type Like 'New%' And User_Id = 'Bob' And Start_Time On Or After 2009-01-01

Here's the statement I have been trying to use:

SELECT DISTINCT person_id FROM person P,service S, service_types ST, service_user SU WHERE P.person_id = S.person_id AND S.service_id = SU.service_id AND ST.type_id = S.service_type_id AND (P.last_name LIKE 'Mar%' OR ST.description LIKE 'Fusions%') OR (ST.description LIKE 'New%' AND SU.user_id = 'Bob' AND start_time >= '2009-01-01')
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
155 views
Welcome To Ask or Share your Answers For Others

1 Answer

Your last condition should be

AND ((P.last_name LIKE 'Mar%' OR ST.description LIKE 'Fusions%') 
OR (ST.description LIKE 'New%' AND SU.user_id = 'Bob' AND start_time >=  2009-01-01'))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...