私はphpMyAdminで作業しています。私は正常に実行され、正確に私が望むものを返すクエリを持っています。同じクエリでビューを作成すると、ビューは正常に作成されます。しかし、私はビューから選択しようとするだけで、私は次のエラーを取得:phpMyAdmin:有効なSQL - >表示、「コマンドが同期していないため、このコマンドをすぐに実行できません」
#2014 - Commands out of sync; you can't run this command now
をここに私のビュースクリプトを作成することです:
CREATE VIEW games_v
AS
[query];
全体的に次のようなクエリです。
SELECT g.game_id,
g.sport_id,
g.season_id,
g.date,
g.away_team_id,
IFNULL(sa.name, g.away_team_name) away_team_name,
sa.city away_city,
(SELECT de.division_id FROM division_enrollment de, school_enrollment se, sports s
WHERE g.sport_id = s.sport_id
AND s.gender = se.gender
AND g.away_team_id = se.school_id
AND g.sport_id = IFNULL(se.sport_id,g.sport_id)
AND g.season_id BETWEEN se.start_year AND se.end_year
AND g.sport_id = de.sport_id
AND g.season_id BETWEEN de.start_year AND de.end_year
AND se.enrollment BETWEEN de.min_enrollment AND de.max_enrollment) away_division,
(SELECT sl.league_id FROM school_leagues sl
WHERE g.sport_id = sl.sport_id
AND g.season_id BETWEEN sl.start_season_id AND IFNULL(sl.end_season_id,100)
AND g.away_team_id = sl.school_id) away_league_id,
(SELECT sl.league_div_id FROM school_leagues sl
WHERE g.sport_id = sl.sport_id
AND g.season_id BETWEEN sl.start_season_id AND IFNULL(sl.end_season_id,100)
AND g.away_team_id = sl.school_id) away_league_div_id,
(SELECT sd.district_id FROM school_districts sd
WHERE g.sport_id = sd.sport_id
AND g.season_id BETWEEN sd.start_season_id AND IFNULL(sd.end_season_id,100)
AND g.away_team_id = sd.school_id) away_district_id,
g.home_team_id,
IFNULL(sh.name, g.home_team_name) home_team_name,
sh.city home_city,
(SELECT de.division_id FROM division_enrollment de, school_enrollment se, sports s
WHERE g.sport_id = s.sport_id
AND s.gender = se.gender
AND g.home_team_id = se.school_id
AND g.sport_id = IFNULL(se.sport_id,g.sport_id)
AND g.season_id BETWEEN se.start_year AND se.end_year
AND g.sport_id = de.sport_id
AND g.season_id BETWEEN de.start_year AND de.end_year
AND se.enrollment BETWEEN de.min_enrollment AND de.max_enrollment) home_division,
(SELECT sl.league_id FROM school_leagues sl
WHERE g.sport_id = sl.sport_id
AND g.season_id BETWEEN sl.start_season_id AND IFNULL(sl.end_season_id,100)
AND g.home_team_id = sl.school_id) home_league_id,
(SELECT sl.league_div_id FROM school_leagues sl
WHERE g.sport_id = sl.sport_id
AND g.season_id BETWEEN sl.start_season_id AND IFNULL(sl.end_season_id,100)
AND g.home_team_id = sl.school_id) home_league_div_id,
(SELECT sd.district_id FROM school_districts sd
WHERE g.sport_id = sd.sport_id
AND g.season_id BETWEEN sd.start_season_id AND IFNULL(sd.end_season_id,100)
AND g.home_team_id = sd.school_id) home_district_id,
(
SELECT
CASE
WHEN sla.league_id != slh.league_id THEN 'N'
WHEN sla.league_id = slh.league_id AND IFNULL(sla.league_div_id,1) = IFNULL(slh.league_div_id,1) THEN 'Y'
WHEN sla.league_id = slh.league_id AND IFNULL(sla.league_div_id,1) != IFNULL(slh.league_div_id,1) THEN (SELECT CASE WHEN ld.div_only = 'Y' THEN 'N' ELSE 'Y' END FROM league_divisions ld WHERE ld.league_id = sla.league_id LIMIT 1)
ELSE 'N'
END
FROM school_leagues sla, school_leagues slh
WHERE g.sport_id = sla.sport_id
AND g.away_team_id = sla.school_id
AND g.season_id BETWEEN sla.start_season_id AND IFNULL(sla.end_season_id, 100)
AND g.sport_id = slh.sport_id
AND g.home_team_id = slh.school_id
AND g.season_id BETWEEN slh.start_season_id AND IFNULL(slh.end_season_id, 100)
) league_game,
g.location,
g.type,
g.time,
g.away_score,
g.home_score
FROM games g
LEFT JOIN schools sa ON sa.school_id = g.away_team_id
LEFT JOIN schools sh ON sh.school_id = g.home_team_id
ここでも、それだけでクエリが正常に実行。しかし、そのクエリを使用して作成されたビューからSELECTを実行しようとすると、上記のエラーで失敗します。
私はOracleの開発者ですので、インラインでなくてもインラインSQL文のいくつかが達成されている可能性がある場合は、事前にお詫びします。私はLEFT JOINとINNER JOINという用語を使用するのに慣れていません.OracleのOuter Joinsにはちょうど(+)を使用していましたので、簡単で(まだ非効率的な)ルートを行っただけです。
解決済み!ここにコードがあります...私のコメントの下で、私はJOINセクション(LEFT/OUTER join)にいくつかのテーブルを追加したところで動作します。私のインラインSELECTの中には何があったのか分かりませんが、今は動作しているようです。
SELECT g.game_id,
g.sport_id,
g.season_id,
g.date,
g.away_team_id,
IFNULL(sa.name, g.away_team_name) away_team_name,
sa.city away_city,
(SELECT de.division_id FROM division_enrollment de, school_enrollment se, sports s
WHERE g.sport_id = s.sport_id
AND s.gender = se.gender
AND g.away_team_id = se.school_id
AND g.sport_id = IFNULL(se.sport_id,g.sport_id)
AND g.season_id BETWEEN se.start_year AND se.end_year
AND g.sport_id = de.sport_id
AND g.season_id BETWEEN de.start_year AND de.end_year
AND se.enrollment BETWEEN de.min_enrollment AND de.max_enrollment) away_division,
sla.league_id away_league_id,
sla.league_div_id away_league_div_id,
sda.district_id away_district_id,
g.home_team_id,
IFNULL(sh.name, g.home_team_name) home_team_name,
sh.city home_city,
(SELECT de.division_id FROM division_enrollment de, school_enrollment se, sports s
WHERE g.sport_id = s.sport_id
AND s.gender = se.gender
AND g.home_team_id = se.school_id
AND g.sport_id = IFNULL(se.sport_id,g.sport_id)
AND g.season_id BETWEEN se.start_year AND se.end_year
AND g.sport_id = de.sport_id
AND g.season_id BETWEEN de.start_year AND de.end_year
AND se.enrollment BETWEEN de.min_enrollment AND de.max_enrollment) home_division,
slh.league_id home_league_id,
slh.league_div_id home_league_div_id,
sdh.district_id home_district_id,
(
SELECT
CASE
WHEN sla.league_id != slh.league_id THEN 'N'
WHEN sla.league_id = slh.league_id AND IFNULL(sla.league_div_id,1) = IFNULL(slh.league_div_id,1) THEN 'Y'
WHEN sla.league_id = slh.league_id AND IFNULL(sla.league_div_id,1) != IFNULL(slh.league_div_id,1) THEN (SELECT CASE WHEN ld.div_only = 'Y' THEN 'N' ELSE 'Y' END FROM league_divisions ld WHERE ld.league_id = sla.league_id LIMIT 1)
ELSE 'N'
END
FROM school_leagues sla, school_leagues slh
WHERE g.sport_id = sla.sport_id
AND g.away_team_id = sla.school_id
AND g.season_id BETWEEN sla.start_season_id AND IFNULL(sla.end_season_id, 100)
AND g.sport_id = slh.sport_id
AND g.home_team_id = slh.school_id
AND g.season_id BETWEEN slh.start_season_id AND IFNULL(slh.end_season_id, 100)
) league_game,
g.location,
g.type,
g.time,
g.away_score,
g.home_score
FROM games g
LEFT JOIN schools sa ON sa.school_id = g.away_team_id
LEFT JOIN schools sh ON sh.school_id = g.home_team_id
LEFT JOIN school_districts sda ON sda.school_id = g.away_team_id AND g.season_id BETWEEN sda.start_season_id AND sda.end_season_id AND g.sport_id = sda.sport_id
LEFT JOIN school_districts sdh ON sdh.school_id = g.home_team_id AND g.season_id BETWEEN sdh.start_season_id AND sdh.end_season_id AND g.sport_id = sdh.sport_id
LEFT JOIN school_leagues sla ON sla.school_id = g.away_team_id AND g.season_id BETWEEN sla.start_season_id AND IFNULL(sla.end_season_id,100) AND g.sport_id = sla.sport_id
LEFT JOIN school_leagues slh ON slh.school_id = g.home_team_id AND g.season_id BETWEEN slh.start_season_id AND IFNULL(slh.end_season_id,100) AND g.sport_id = slh.sport_id
私は私の問題を解決しました。クエリを見る時間が増えた後、私は外部結合リストにさらにいくつかのテーブルを追加して動作させました。私はまだそれらのすべてを完了していないが、私が修正したものは問題を解決したようだ。 – thePITman