sql server - Is it possible to optimize this ms sql query? -
this query little slows access frontend/ sql backend application halt. there way optimize it?
from can understand displays cid , weeknr of lastly culturestepid.
select distinct culture.cid, (select top (1) weeknr culturestep (cultureid = culture.cid) order culturestepid) normalstartweek civilization inner bring together culturestep on culture.cid= culturestep.cid
edit:
number of rows query: 2309
culturestep table: 13961
culture table: 2472
try this:
first solution (you show civilization indipendent existence of culturestep):
select culture.cid, (select cs.weeknr culturestep cs (cs.cultureid = culture.cid) , not exists( select 'next' culturestep cs2 cs2.cultureid = cs.cultureid , cs2.culturestepid > cs.culturestepid) ) normalstartweek civilization
second solution: (you show civilization if exists linked culturestep):
select culture.cid, (select cs.weeknr culturestep cs (cs.cultureid = culture.cid) , not exists( select 'next' culturestep cs2 cs2.cultureid = cs.cultureid , cs2.culturestepid > cs.culturestepid) ) normalstartweek civilization exists( select 'culturestep' culturestep (cultureid = culture.cid) )
sql sql-server
No comments:
Post a Comment