Ich habe viele Anfragen bekommen, die wie geschrieben werden:Wie optimieren verschachtelte Abfrage
select thread_id as topic_id,title as topic
,
isnull((select count(*) from tblmessages b where thread_id=a.thread_id and is_approved='Y' and sort_level>1
group by b.thread_id
),0) as replies,
isnull((select count(*) from tblmessages b where thread_id=a.thread_id and isnull(new_post,'Y')='Y' and sort_level>1
group by b.thread_id
),0) as NewPost,
isnull((select count(*) from tblmessages b where thread_id=a.thread_id and isnull(is_approved,'N')='N' and sort_level>1
group by b.thread_id
),0) as NotClear,
sort_level,sort_index, from tblMessages a
where sort_level=1 and [email protected]
order by topic_id desc
Bitte sagen Sie mir, wie zu optimieren und eine bessere Art und Weise solche Abfragen zu schreiben. weil ich Tabellen mit Aufzeichnungen 5,00,000 habe. Es braucht also viel Zeit und manchmal kommt eine Auszeit.
Dank
Sind das fünf Millionen oder 50 Millionen Datensätze? –
@Marcele: seine 5,00,000 –