当前位置: 代码迷 >> ASP.NET >> SQL过滤重复项有关问题
  详细解决方案

SQL过滤重复项有关问题

热度:8677   发布时间:2013-02-25 00:00:00.0
SQL过滤重复项问题
SELECT DBW.ID AS ID,
  TD.ID AS DRIVER_ID,
  convert(varchar(10),DBW.START_VALID_TIME,121) as START_VALID_TIME,
  DBW.BASIC_WAGE AS BASIC_WAGE,
  DBW.IS_VALID AS IS_VALID,
  TD.WORK_CARDNO,
  TD.DRIVER_NAME
  FROM TRUCK_DRIVER TD LEFT JOIN
  DRIVER_BASIC_WAGE DBW ON (DBW.DRIVER_ID=TD.ID)
  我想做到DRIVER_ID 去掉重复项 也就是DRIVER_ID相同的情况下只显示一项
怎么改SQL

------解决方案--------------------------------------------------------
SELECT DBW.ID AS ID,TD.ID AS DRIVER_ID,convert(varchar(10),DBW.START_VALID_TIME,121) as START_VALID_TIME,DBW.BASIC_WAGE AS BASIC_WAGE,DBW.IS_VALID AS IS_VALID,
TD.WORK_CARDNO,
TD.DRIVER_NAME
FROM TRUCK_DRIVER TD LEFT JOIN
DRIVER_BASIC_WAGE DBW ON (DBW.DRIVER_ID=TD.ID)
where DRIVER_ID in (select distinct TD.ID From TRUCK_DRIVER)
union
SELECT DBW.ID AS ID,TD.ID AS DRIVER_ID,convert(varchar(10),DBW.START_VALID_TIME,121) as START_VALID_TIME,DBW.BASIC_WAGE AS BASIC_WAGE,DBW.IS_VALID AS IS_VALID,
TD.WORK_CARDNO,
TD.DRIVER_NAME
FROM TRUCK_DRIVER TD LEFT JOIN
DRIVER_BASIC_WAGE DBW ON (DBW.DRIVER_ID=TD.ID)
where DRIVER_ID!=''
  相关解决方案