Sybase Select Statement

非 Y 不嫁゛ 提交于 2019-12-13 08:05:15

问题


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')

回答1:


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'))


来源:https://stackoverflow.com/questions/21123140/sybase-select-statement

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!