表A的结构如下:
车牌号码(cphm) 车辆类型(cllx)驾驶员姓名(jsyxm) 驾驶证号(jszh) 违法时间(wfsj)违法代码(wfdm)注:酒后驾驶的违法代码1101
   超速驾驶的违法代码1103
   超员行驶的违法代码1109查询A表中酒后驾驶,一年内有三次有超速,一年内4次超员违法行为的记录谢谢各位!!!

解决方案 »

  1.   

    --try
    select cphm,year(wfsj)
    from tablea
    group by cphm,year(wfsj)
    having sum(case when wfdm=1101 then 1 else 0 end)>=1
    and sum(case when wfdm=1103 then 1 else 0 end)>=3
    and sum(case when wfdm=1109 then 1 else 0 end)>=4
      

  2.   

    查询A表中酒后驾驶,一年内有三次有超速,一年内4次超员违法行为的记录是and关系还是or关系?
      

  3.   

    select cphm,year(wfsj)
    from tablea
    group by cphm,year(wfsj)
    where datediff(yy,wfsj,getdate())<1
    having sum(case when wfdm=1101 then 1 else 0 end)>=1
    and sum(case when wfdm=1103 then 1 else 0 end)>=3
    and sum(case when wfdm=1109 then 1 else 0 end)>=4