本文介绍了Sybase Select语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试在某些特定条件下进行选择,但似乎无法获得我想要的东西.

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

餐桌人物person_id | first_name |姓

Table Personperson_id | first_name | last_name

餐桌服务service_id | person_id | start_time |结束时间| service_type_id

Table Serviceservice_id | person_id | start_time | end_time | service_type_id

表Service_Typestype_id |说明

Table Service_Typestype_id | description

表Service_Userservice_id | start_time | end_Time | user_id

Table Service_Userservice_id | start_time | end_Time | user_id

目标是获取满足以下任何条件的所有person_id:

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

  1. "Mar%"之类的姓氏
  2. 融合%"之类的服务类型
  3. 2009年1月1日或之后的"New%"和User_Id ="Bob"且Start_Time之类的服务类型

这是我一直在尝试使用的语句:

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

推荐答案

您的最后一个条件应该是

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

这篇关于Sybase Select语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 21:39