现有4个表,表定义如下:
P(P_ID,P_Name,P_Desc)
A(A_ID,P_ID,A_Name,A_Desc)
B(B_ID,P_ID,B_Name,B_Desc)
C(C_ID,C_Date,C_Time,P_ID,A_ID,B_ID,C_TimeLong,C_FileName)我想从C表中查出C_Date在2009-10-01到2009-10-25日之间的,且 A_Name存在‘广电总局‘文本或B_Name 存在‘广电总局‘文本的所有记录,需要查询出C_Date,C_Time,A_Name,B_Name,C_FileName,C_TimeLong,请高手指教?

解决方案 »

  1.   


    select C.C_Date,C.C_Time,A.A_Name,B.B_Name,C.C_FileName,C.C_TimeLong from C
        left join B on B.B_ID=C.B_ID
        left join A on A.A_ID=C.A_ID
            where B.B_Name like '%广电总局%' and A.A_Name like '%广电总局%'
           and C_Date between '2009-10-01' and '2009-10-25'
      

  2.   

    select 
     c.C_Date,c.C_Time,a.A_Name,b.B_Name,c.C_FileName,c.C_TimeLong
    from
     p,a,b,c
    where 
     c.C_Date between '2009-10-01' and '2009-10-25'
    and
     a.name like '广电总局%' or b.name like '广电总局%'
    and
     p.p_id=a.p_id and p.p_id=b.p_id and p.p_id=c.p_id  and a.A_ID=c.A_ID and b.B_ID=c.B_ID
      

  3.   

    select c.C_Date,c.C_Time,a.A_Name,b.B_Name,c.C_FileName,c.C_TimeLong 
    from P,A,B,C
    where p.pid=a.pid=b.pid=c.pid
    and a.A_Name like '%广电总局%'
    and b.B_Name like '%广电总局%'
      

  4.   

    select c.C_Date,c.C_Time,a.A_Name,b.B_Name,c.C_FileName,c.C_TimeLong 
    from  p,a,b,c 
    where  p.p_id=a.p_id and p.p_id=b.p_id and p.p_id=c.p_id and a.A_ID=c.A_ID and b.B_ID=c.B_ID
    and c.C_Date between '2009-10-01' and '2009-10-25'
     and  a.name like '%广电总局%' or b.name like '%广电总局%' 
      

  5.   

    select C_Date,C_Time,A_Name,B_Name,C_FileName,C_TimeLong
    from P
    Left Join A On P.P_ID=A.P_ID
    Left Join B On P.P_ID=B.P_ID
    left join C On P.P_ID=C.P_ID and A.A_ID=C.A_ID and B.B_ID=C.B_ID
    where convert(nvarchar(10),C_Date,120) between '2009-10-01' and '2009-10-25'
    and (A.A_Name like '%广电总局%' or B.B_Name like '%广电总局%')
      

  6.   

    select c.C_Date,c.C_Time,a.A_Name,b.B_Name,c.C_FileName,c.C_TimeLong 
    from P,A,B,C
    where p.pid=a.pid=b.pid=c.pid
    and a.A_Name like '%广电总局%'
    and b.B_Name like '%广电总局%'