1
有些人可能會認爲這不是一個複雜的陳述,但對我來說(因爲我只做了約一個月的陳述),這是一個。以下語句返回我正在查找的確切結果,但我的問題是,它需要95秒才能在iMac上運行。我需要這個聲明在iPhone上運行。任何人都可以以更好(更快)的方式來做到這一點?SQLITE複雜選擇語句。幫助我加快它
select categories.category
from categories join categories_listings
where categories_listings.category_id = categories.id
and categories.association_id = 1
and (select count(*)
from (select (
select categories.category
from categories left join categories_listings
where categories_listings.category_id = categories.id
and categories.association_id = 1
and listings.id = categories_listings.listing_id) as region
from listings left join chamber_specifics
on chamber_specifics.listing_id=listings.id
where region = categories.category
and listings.association_id=1
and listings.status = 1
and downtown='Y')) >0
group by categories.category;
讓我知道是否需要更多信息。
謝謝!
試圖編輯那個怪物後,我會說:是的,這很複雜。你的第一個'join'沒有'ON'子句...我不認爲你需要'count(*)'子句 - 只需選擇所有記錄並進行一次'IN'檢查。 – Rudu 2012-02-15 18:02:05
對不起,怪物。我感謝你的意見。我現在正在修改它,以包含一個ON子句並執行IN檢查。我會讓你知道結果如何。謝謝! – KevinM 2012-02-15 18:54:52