实现类似百度的搜索功能,模糊查出好几个字段拼接到一起,现有表:LearnPhase(学段-包含ID,名称)
QuestionTypes(题型-包含ID,名称)
题库主表Question(包含学段ID,题型ID,难度-tinyint,知识点1,知识点2)
题库子表(子表ID,和主表关联ID,题干,答案)比如我在搜索里输入 选择题(题型--主表只有ID,要去QuestionTypes查)当然这个是不确定的,也可以输入学段、难度,然后模糊搜索出(题库主表中的学段,题型,难度,知识点,子表的题干,答案)信息--PS:搜索出的学段,题型等为中文,也就是其他表的Name,这个SQL语句应该怎么写?期待高手的到来……

解决方案 »

  1.   

    select t1.学段,t1.名称 as 学段名称,t2.题型,t2.名称 as 题型名称,t3.难度,t3.知识点1,t3.知识点2,t4.题干,t4.答案
    from LearnPhase t1,QuestionTypes t2,题库主表Question t3,题库子表 t4
    where t1.学段=t3.学段 and t2.题型=t3.题型 and t3.ID=t4.主表关联ID  --题库主表应该有个ID和字表对应
    and (t1.名称 like '%你的输入值%' or t2.名称 like '%你的输入值%')
      

  2.   

    select * from Question a
    left outer join LearnPhase b on a.学段id=b.学段id
    left outer join LearnPhase c on a.题型id=c.题型id
    left outer join 题库子表 d on a.主表id=d.主表id
    where 1=1 ....