selectcount(*) from tableA where id >2000000and id <3000000; selectcount(*) from tableB where id >2000000and id <3000000; selectcount(*) from tableC where id >2000000and id <3000000; selectcount(*) from tableD where id >2000000and id <3000000;
结果:
分析:因为表A C拥有主键id,因此查询速度快,其与两表查询速度接近。
Q2:查询dense段大于5的记录条数
查询语句:
1 2 3 4
selectcount(*) from tableA where dense >5; selectcount(*) from tableB where dense >5; selectcount(*) from tableC where dense >5; selectcount(*) from tableD where dense >5;
selectcount(*) from tableA where sparse <150000; selectcount(*) from tableB where sparse <150000; selectcount(*) from tableC where sparse <150000; selectcount(*) from tableD where sparse <150000;
selectcount(*) from tableA where sparse <150000and dense >5; selectcount(*) from tableB where sparse <150000and dense >5; selectcount(*) from tableC where sparse <150000and dense >5; selectcount(*) from tableD where sparse <150000and dense >5;
createtrigger add_sell after inserton sells foreachrow begin declare total_money int ; selectsum(sells.quantity * fruits.price) into total_money from sells innerjoin fruits on sells.fid = fruits.fid where cid = NEW.cid; if total_money <10000then update customer set level ='normal'where cid = NEW.cid; else if total_money >=10000and total_money <20000then update customer set level ='VIP'where cid = NEW.cid; else update customer set level ='SVIP'where cid = NEW.cid; end if; end if; end;
createtrigger delete_sell after deleteon sells foreachrow begin declare total_money int ; selectsum(sells.quantity * fruits.price) into total_money from sells innerjoin fruits on sells.fid = fruits.fid where cid = OLD.cid; if total_money <10000then update customer set level ='normal'where cid = OLD.cid; else if total_money >=10000and total_money <20000then update customer set level ='VIP'where cid = OLD.cid; else update customer set level ='SVIP'where cid = OLD.cid; end if; end if; end;
createtrigger update_sell after updateon sells foreachrow begin declare total_money int ; selectsum(sells.quantity * fruits.price) into total_money from sells innerjoin fruits on sells.fid = fruits.fid where cid = NEW.cid; if total_money <10000then update customer set level ='normal'where cid = NEW.cid; else if total_money >=10000and total_money <20000then update customer set level ='VIP'where cid = NEW.cid; else update customer set level ='SVIP'where cid = NEW.cid; end if; end if; end;