0

私はSQLを初めて使用するため、SQLクエリを拡張する際にいくつかの問題に直面しています。

基本的に2つのテーブルがあります。1つはef_dat_app_ef_linkで、もう1つはef_dat_lspd_machine_type_modelです。

これが私が話しているクエリです。すべての問題のベースとなる10行目に内部結合を追加しました。

select country_isocode as country,
language_isocode as language, model_number,
machine_type_model_name model_name,machine_type_group_id,
machine_type_model_id, product_type_name product_type,
machine_type_model_id_to,filenet_link 
from ef_dat_lspd_machine_type_model,
cross join ef_dim_lspd_country_language
left join ef_dat_lspd_model_country 
using (machine_type_model_id, country_isocode)
inner join ef_dat_app_ef_link on  (ef_dat_lspd_machine_type_model.lpmd_revenue_pid = ef_dat_app_ef_link.ef_product_revenue_pid)
where (ef_dat_app_ef_link.country_isocode='US' or ef_dat_app_ef_link.country_isocode='CA') and ef_dat_app_ef_link.language_isocode='en'
join ef_dat_lspd_product_type using (product_type_id)
left join ef_dat_lspd_model_relationship on (machine_type_model_id_from = machine_type_model_id) 
where (discontinue_date is null or discontinue_date > sysdate) and
(announce_date is null or announce_date <= sysdate)
and (machine_type_model_id in (select machine_type_model_id from ef_dat_lspd_model_parts)
or not machine_type_model_id_to is null) order by machine_type_model_id

以下は、私が取り組むことになっている変更されていないクエリです。

select  country_isocode as country,
language_isocode as language,


machine_type_model_id,
product_type_name product_type,machine_type_model_id_to,
image_url
from ef_dat_lspd_machine_type_model cross join ef_dim_lspd_country_language 
left join ef_dat_lspd_model_country using (machine_type_model_id, country_isocode) 
join ef_dat_lspd_product_type using (product_type_id) 
left join ef_dat_lspd_model_relationship on (machine_type_model_id_from =    machine_type_model_id)
where (discontinue_date is null or discontinue_date > sysdate) and
(announce_date is null or announce_date <= sysdate) and
(machine_type_model_id in (select machine_type_model_id from ef_dat_lspd_model_parts) or >not machine_type_model_id_to is null)
order by machine_type_model_id

これで、ef_dat_app_ef_linkテーブルに、画像、国コード、言語コード、および収益IDを含むリンクがあり、もう1つは画像リンクとさらにいくつかの列を含むef_dat_lspd_machine_type_modelです。私がやろうとしているのは、このテーブルの収益IDが他のテーブルの収益IDと等しいef_dat_app_ef_linkテーブルからのプルアップ画像を置き換えるクエリを作成することです。テーブルを収益IDで検索すると、多くの列が表示されます。そのため、言語が「en」、国が「US」または「CA」の行をプルアップしたいと思います。

同じ効果に内部結合ステートメントを追加しましたが、キーワードが見つからない場合は常にORA00905エラーがスローされます。

行った変更をイタリック体で示しています。コードのそのような悪い表現で申し訳ありません。見栄えを良くする方法の頭や尻尾を作ることができませんでした。

4

2 に答える 2

2

既存のクエリの途中にWHERE句のsmackdabを追加しました。クエリに複数のWHERE句を含めることはできません。また、テーブル結合の途中に配置することもできません。

図解された問題

追加したWHERE句を既存の句にマージします(スナップショットの緑色の矢印で示されています)。

于 2012-05-31T10:56:30.033 に答える
1

あなたがそれをしなければならないような構造を混ぜることはできません

select *
from t
join t1
join t2
where 
and
or
order by

あなたはこれを行うことはできません

select *
from t
join t2
where
order 
join 
where
order 

試す

select country_isocode as country,
language_isocode as language, model_number,
machine_type_model_name model_name,machine_type_group_id,    
machine_type_model_id, product_type_name product_type,
machine_type_model_id_to,filenet_link 
from ef_dat_lspd_machine_type_model
cross join ef_dim_lspd_country_language
left join ef_dat_lspd_model_country 
using (machine_type_model_id, country_isocode)
inner join ef_dat_app_ef_link on  (ef_dat_lspd_machine_type_model.lpmd_revenue_pid = ef_dat_app_ef_link.ef_product_revenue_pid)
join ef_dat_lspd_product_type using (product_type_id)
left join ef_dat_lspd_model_relationship on (machine_type_model_id_from = machine_type_model_id) 
where (ef_dat_app_ef_link.country_isocode='US' or ef_dat_app_ef_link.country_isocode='CA') and ef_dat_app_ef_link.language_isocode='en'
and (discontinue_date is null or discontinue_date > sysdate) and
(announce_date is null or announce_date <= sysdate)
and (machine_type_model_id in (select machine_type_model_id from ef_dat_lspd_model_parts)
or not machine_type_model_id_to is null) order by machine_type_model_id
于 2012-05-31T10:56:05.727 に答える