select count(*) from record where date >'19991201' and date < '19991214'and amount >2000 (25秒) select date,sum(amount) from record group by date(55秒) select count(*) from record where date >'19990901' and place in ('bj','sh') (27秒)
select count(*) from record where date >'19991201' and date < '19991214' and amount >2000(14秒) select date,sum(amount) from record group by date(28秒) select count(*) from record where date >'19990901' and place in ('bj','sh')(14秒)
select count(*) from record where date >'19991201' and date < '19991214' and amount >2000(26秒) select date,sum(amount) from record group by date(27秒) select count(*) from record where date >'19990901' and place in ('bj, 'sh')(< 1秒)
---- 4.在date,place,amount上的組合索引 select count(*) from record where date >'19991201' and date < '19991214' and amount >2000(< 1秒) select date,sum(amount) from record group by date(11秒) select count(*) from record where date >'19990901' and place in ('bj','sh')(< 1秒)
select * from record where substring(card_no,1,4)='5378'(13秒) select * from record where amount/30< 1000(11秒) select * from record where convert(char(10),date,112)='19991201'(10秒)
select * from record where card_no like '5378%'(< 1秒) select * from record where amount < 1000*30(< 1秒) select * from record where date= '1999/12/01' (< 1秒)
select count(*) from stuff where id_no='0' select count(*) from stuff where id_no='1'
---- 得到兩個(gè)結(jié)果,再作一次加法合算。因?yàn)槊烤涠际褂昧怂饕瑘?zhí)行時(shí)間只有3秒,在620000行下,時(shí)間也只有4秒。或者,用更好的方法,寫一個(gè)簡(jiǎn)單的存儲(chǔ)過(guò)程: create proc count_stuff as declare @a int declare @b int declare @c int declare @d char(10) begin select @a=count(*) from stuff where id_no='0' select @b=count(*) from stuff where id_no='1' end select @[email protected][email protected] select @d=convert(char(10),@c) print @d