学生表:t_stu
stu_ID class_ID stu_no
班级表:t_class
class_ID class_name class_no
学科表:t_sub
sub_ID sub_name class_ID已评表:t_passMsgpassMsg_ID stu_ID stage现在的条件是t_passMsg.stu_ID = t_stu.stu_ID and t_stu.class_ID = t_class.class_ID and class_no = '20100401' and t_sub.class_ID = t_class.class_ID and sub_name = '语文'现在我写的sql:
select stage from t_passMsg,t_stu,t_class,t_sub where t_passMsg.stu_ID = t_stu.stu_ID and t_stu.class_ID = t_class.class_ID and class_no = '20100401' and t_sub.class_ID = t_class.class_ID and sub_name = '语文'我觉得这样写太麻烦了,也不美观。谁能帮我优化一下。

解决方案 »

  1.   


    select stage from t_passMsg as tp,t_stu as ts,t_class as tc,t_sub as t where tp.stu_ID = ts.stu_ID and ts.class_ID = tc.class_ID and class_no = '20100401' and t.class_ID = tc.class_ID and sub_name = '语文'
    楼主你连字段名都没说,让我们在这猜吗;还有你最好有测试数据,比如表里有什么数据,然后你需要的数据是什么样的
      

  2.   

    select
     stage 
    from
     t_passMsg a ,t_stu b ,t_class c,t_sub d
    where
     a.stu_ID =d.stu_ID 
    and
     b.class_ID = c.class_ID 
    and
     b.class_no = '20100401' 
    and
     d.class_ID = c.class_ID 
    and
     d.sub_name = '语文'
      

  3.   


    select stage from t_passMsg msg join t_stu stu on msg.stu_ID = stu.stu_ID join t_class class on stu.class_ID = class.class_ID join t_sub sub on sub.class_ID = class.class_ID 
    where sub.sub_name = '语文' and class.class_no = '20100401'