此查询将拉动所有在列文件名
中具有无线电或荧光许可证的医生select practitioner_id_numbers.pract_id
, practitioner_id_numbers.id_number
, practitioner_id_numbers.expiration_date
, practitioner_id_numbers.documentname
, practitioner_id_numbers.historical
from practitioner_id_numbers
group by practitioner_id_numbers.pract_id
, practitioner_id_numbers.id_number
, practitioner_id_numbers.expiration_date
, practitioner_id_numbers.documentname
, practitioner_id_numbers.historical
having (((practitioner_id_numbers.documentname) like "Radio*"
or (practitioner_id_numbers.documentname) like "Fluoro*")
and ((practitioner_id_numbers.historical)=0));
答案 0 :(得分:4)
Microsoft Access创建自己的SQL版本,这实际上很烦人,因为它实际上向DBMS本身呈现了正确的SQL - 它只是不会将它暴露给最终用户。如果要使此DBMS兼容,则需要考虑Access为表创建了别名,并将架构/表分隔符从点转换为下划线。
因此,根据您的表名是practitioner.id_numbers
还是practitioner_id.numbers
,SQL会有所不同 - 假设它是后者,Oracle SQL将是:
select practitioner_id.numbers.pract_id
, practitioner_id.numbers.id_number
, practitioner_id.numbers.expiration_date
, practitioner_id.numbers.documentname
, practitioner_id.numbers.historical
from practitioner_id.numbers
group by practitioner_id.numbers.pract_id
, practitioner_id.numbers.id_number
, practitioner_id.numbers.expiration_date
, practitioner_id.numbers.documentname
, practitioner_id.numbers.historical
having (((practitioner_id.numbers.documentname) like 'Radio%'
or (practitioner_id.numbers.documentname) like 'Fluoro%')
and ((practitioner_id.numbers.historical)=0));
另请注意,在Access中,双引号变为值的单个引号,而星号变为百分号。
要在Access中使相同的SQL工作,您可以将其作为pass-thru查询运行,然后您的代码将从那时开始可移植。唯一的缺点是,如果你进行pass-thru,你就不能再在Access中使用设计器了。
尽管如此,Access的另一个危险是,当having
成为首选时,它往往会过度使用where
。假设标准消除了大量行,以下代码在Oracle方面将更加高效:
select practitioner_id.numbers.pract_id
, practitioner_id.numbers.id_number
, practitioner_id.numbers.expiration_date
, practitioner_id.numbers.documentname
, practitioner_id.numbers.historical
from practitioner_id.numbers
where (((practitioner_id.numbers.documentname) like 'Radio%'
or (practitioner_id.numbers.documentname) like 'Fluoro%')
and ((practitioner_id.numbers.historical)=0))
group by practitioner_id.numbers.pract_id
, practitioner_id.numbers.id_number
, practitioner_id.numbers.expiration_date
, practitioner_id.numbers.documentname
, practitioner_id.numbers.historical
而且,只是为了咧嘴笑,如果你想让它变得更加惯用,你可以添加别名并将group by
更改为distinct
(因为你似乎并没有真正使用分组功能):
select distinct
pi.pract_id
, pi.id_number
, pi.expiration_date
, pi.documentname
, pi.historical
from practitioner_id.numbers as pi
where
((pi.documentname like 'Radio%' or
pi.documentname like 'Fluoro%') and
pi.historical=0)