select Num,Customer_Name,ETA,Ship_Mode
from tb a
where exists
(select * from tb where Container=a.Container and Customer_Name<>a.Customer_Name and right(rtrim(ltrim(Container)),2)='CY')

解决方案 »

  1.   

    select * from tb where Container in
    (select Container from tb where right(Ship_Mode,2) = 'CY' group by Container having count(*) > 1)
      

  2.   

    谢谢楼上两位帮助,但出现错误,查询不了.或者再说详细一点
    1.查询某一段日期内(如2008-10-1至2008-10-31)
    2.Ship_Mode这个字段中的数据是最后两位数是"CY"的
    3.Container这个字段中相同的但Customer_Name中不相同的数据
    4.输出数据库中出全部符合以上结果的所有字段的数据数据库名称:Web_Bargain我原来写的语句是这样的:
    Select * from (select ID,Num,Factory_Make,Handled,ETD,Amt,Unit,BL,Customer_Name,Container,ETA,Modify_Time from (select count(*) as counts,ID,Num,Factory_Make,Handled,ETD,Amt,Unit,BL,Customer_Name,Container,ETA,Modify_Time from Web_Bargain where Ship_Mode Like '%CY' group by ID,Num,Factory_Make,Handled,ETD,Amt,Unit,BL,Customer_Name,ETA,Container,Modify_Time) as t1 where counts>0 group by ID,Num,Factory_Make,Handled,ETD,Amt,Unit,BL,Customer_Name,Container,ETA,Modify_Time) as t2 where ETA Between #"& Search_Key &"# and #"& Search_Key2 &"#" 但不符合我所要查询的结果。
      

  3.   

    谢谢楼上两位的帮助,在你们的提示现,我解决了问题,三楼的楼主查询出来的结果与我写查询出来的结果是一样的,但你的精简很多,查询出来的结果只能是Container相同,但不能分出Customer_Name不同的结果,最后还是感谢两位热心人事的帮助,谢谢
      

  4.   

    那也把你解决的sql发出来看看