题目如下:
1.User表有name和birthday两个字段,B表只有celebrity一个字段,要求取出user的name,条件是birthday存在于B表的celebrity字段中,现有的Sql语句是select name from User where birthday in (select celebrity from B),要求优化这段Sql语句。
注:我的方案是 select name from User where birthday in (select distinct celebrity from B. 可能没优化多少。2.从A表中取出数据,根据count(VARCHAR2(10))字段进行检索,把count是10的数据取出来,下面的SQL文性能有点低,请写出性能高的2个SQL文
  SELECT * FROM A WHERE count=103.有以下SQL文,为提高性能,请对其进行修改(userTable没有index)
SELECT‘not found’FROM userTable WHERE memberid◇‘aaaa’4.从SomeTable表中取出数据,根据col_1(VARCHAR2(10))字段进行模糊查询,下面的SQL文性能有点低,请写出性能高的一个SQL文
  SELECT * FROM SomeTable WHERE col_1 LIKE‘%a%’;

解决方案 »

  1.   

    1.select name from user left join B On user.birthday = B.celbrity
      

  2.   

    1.User表有name和birthday两个字段,B表只有celebrity一个字段,要求取出user的name,条件是birthday存在于B表的celebrity字段中,现有的Sql语句是select name from User where birthday in (select celebrity from B),要求优化这段Sql语句。
    注:我的方案是 select name from User where birthday in (select distinct celebrity from B. 可能没优化多少。
    显然如果你的B表中celebrity不是主键,有重复的话,下面的语句比较合适。
    select name from User where exists (select 1 from B where celebrity=birthday)
      

  3.   

    2.从A表中取出数据,根据count(VARCHAR2(10))字段进行检索,把count是10的数据取出来,下面的SQL文性能有点低,请写出性能高的2个SQL文
     SELECT * FROM A WHERE count=10

    SELECT * FROM A WHERE count='10'另外需要在count 字段上创建索引。
      

  4.   

    3.有以下SQL文,为提高性能,请对其进行修改(userTable没有index)
    SELECT‘not found’FROM userTable WHERE memberid◇‘aaaa’
    无法继续优化。除非创建索引。4.从SomeTable表中取出数据,根据col_1(VARCHAR2(10))字段进行模糊查询,下面的SQL文性能有点低,请写出性能高的一个SQL文
     SELECT * FROM SomeTable WHERE col_1 LIKE‘%a%’;
    无法继续优化。除非创建全文索引。
      

  5.   

    1
    select name from User a inner join  (select distinct celebrity from B) b
    on a.birthday=b.celebrity
    2
    SELECT * FROM A WHERE count=10
    在 count上建立索引
    3
    为什么不建立索引
    4
    %a%:无法用到索引,a%这种可以
      

  6.   

    3.有以下SQL文,为提高性能,请对其进行修改(userTable没有index)
    SELECT‘not found’FROM userTable WHERE memberid◇‘aaaa’
    无法继续优化。除非创建索引。
    ******************************************这个"<>"(不等于)建了索引也会进行全部检索,没法优化.
      

  7.   

    http://topic.csdn.net/u/20100716/09/17816446-de83-4917-b44a-7c4e3489f907.html这个帖子里回答得更好些,大家有空可以去看看。