我有一个表,其中有五条数据,其中答题流水号,姓名等都相同,但日期不同,我想把相同的流水号合并,并提取最新的日期显示在上面,怎么显示,distinct语句是这样的
select distinct groupid_top,kh,xm,xb,nl,fdbh from GLZX_WJDTB_ZB WHERE 1=1合并后的结果如下图,但要加上最新日期,语句怎么写
c# distict  合并select

解决方案 »

  1.   

    select distinct max(日期),groupid_top,kh,xm,xb,nl,fdbh from GLZX_WJDTB_ZB WHERE 1=1
      

  2.   


    select [答题流水号],[姓名],max([日期]) from 你的表
    group by [答题流水号],[姓名]
      

  3.   

    我试了下,可是出现以下错误
    服务器无法处理请求。 ---> ORA-00937: 不是单组分组函数
      

  4.   

    select * from GLZX_WJDTB_ZB where in in(select max(id) from GLZX_WJDTB_ZB group by 流水号)
      

  5.   

    我试了下,可是出现以下错误
    select distinct max(日期),groupid_top,kh,xm,xb,nl,fdbh from GLZX_WJDTB_ZB WHERE 1=1
    服务器无法处理请求。 ---> ORA-00937: 不是单组分组函数
      

  6.   


    用2楼的方法,使用group by吧。
      

  7.   

    我1楼只是给了一个方向。参考:
    select 流水号,max(日期) from GLZX_WJDTB_ZB group by 流水号
      

  8.   

    select distinct groupid_top,kh,xm,xb,nl,fdbh,
    (select max(日期) frm glzx_wjdtb_zb b where b.groupid_top = a.groupid_top
    and a.kh = b.kh and a.xm = b.xm --这个条件你自己定
    ) 日期
     from GLZX_WJDTB_ZB a WHERE 1=1
      

  9.   

    已用group by方法解决,谢谢各位
    string strLBMC = "select groupid_top,kh,xm,xb,nl,max(rq),fdbh from GLZX_WJDTB_ZB where fdbh = '" + s + "'and  group by groupid_top,kh,xm,xb,nl,fdbh ";