您好,欢迎来到[编程问答]网站首页   源码下载   电子书籍   软件下载   专题
当前位置:首页 >> 编程问答 >> .NET >> distinct 问题。。。。求大神

distinct 问题。。。。求大神

来源:网络整理     时间:2016/5/11 3:53:33     关键词:distinct

关于网友提出的“distinct 问题。。。。求大神”问题疑问,本网通过在网上对“distinct 问题。。。。求大神”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题:distinct 问题。。。。求大神
描述:

我就想根据这个 CarBrand 来去掉重复数据 不知道可不可以》??帮忙看看代码

distinct 用法,sql distinct,distinctive,distinction,mysql distinct,oracle distinct,distinct 多个字段,select distinct,sql去重distinctdistinct 用法,sql distinct,distinctive,distinction,mysql distinct,oracle distinct,distinct 多个字段,select distinct,sql去重distinctView Code

select distinct (t1.CarBrand), t1.id, 
t1.CarName,t1.CarColor,t1.CarType,t1.CarNotes,
t1.CarState,t1.WingNum,t1.NumL,t1.SeatNum,t1.DangWei,
t1.CompanyId,t1.ShopsId,t1.Grade,t1.CarPrice,t1.FestivalPrice,
t1.WeekendPrice,t1.PrePrice,t1.Range,t1.ServicePrice,t1.OutRangePrice,
t1.OutTimePrice,t1.ProtectPrice,t1.IsOil,t1.IsDriver,t1.IsLuqiao,
t1.ServiceTime,t2.ShopName,t2.ShopAddress,t2.AreaCode,dbo.Fun_CarACityById(t2.CityCode) as CityCode,
dbo.FunCarBrandById(t1.CarBrand) as CarBrandName,t1.TJJG,t1.BegTime,t1.TJ,t1.Image,t1.EndTime
from CarInfo t1 left join CompanyShops t2 on (t1.ShopsId=t2.Id)  order by t1.CarBrand

CarBrand  是数字。。。


解决方案1:

select * from
(
 SELECT A.* FROM
 (
  select distinct (t1.CarBrand), t1.id,
  t1.CarName,t1.CarColor,t1.CarType,t1.CarNotes,
  t1.CarState,t1.WingNum,t1.NumL,t1.SeatNum,t1.DangWei,
  t1.CompanyId,t1.ShopsId,t1.Grade,t1.CarPrice,t1.FestivalPrice,
  t1.WeekendPrice,t1.PrePrice,t1.Range,t1.ServicePrice,t1.OutRangePrice,
  t1.OutTimePrice,t1.ProtectPrice,t1.IsOil,t1.IsDriver,t1.IsLuqiao,
  t1.ServiceTime,t2.ShopName,t2.ShopAddress,t2.AreaCode,dbo.Fun_CarACityById(t2.CityCode) as CityCode,
  dbo.FunCarBrandById(t1.CarBrand) as CarBrandName,t1.TJJG,t1.BegTime,t1.TJ,t1.Image,t1.EndTime
  from CarInfo
 ) inner join A
 (select max(id) from b group by CarName) B on A.id=B.id
) t1 left join CompanyShops t2 on (t1.ShopsId=t2.Id) 
order by t1.CarBrand

自己调试下试试

解决方案2:

distinct只能针对一个字段,其他字段如果想要一起查询出来就必须按照这个字段区分后能分组,否则会有问题。比如学校里面根据老师distinct,那么其他想要一起查询出来的只能是课程(只教语文的)或者班级(只负责教一个班的)这种跟老师能一起区分的,学生就不能查出来了,因为一个老师带了很多学生,你这个查询把其他项都去掉肯定没问题,但是现在肯定不行的你。要么就多用几个sql语句吧一步一来

解决方案3:

你是想怎样?是只要CarBrand重复,不管其它字段重复不重复,都认为是重复,然后在这些重复的记录中随机还是按什么规则选取一条记录。还是说多条记录的多个字段数据相同才算重复?

不过你写的行不通吧。。

解决方案4:

你的需求是什么,distinct只能针对一个字段,你这样写是不行的


以上介绍了“distinct 问题。。。。求大神”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/1019419.html

相关图片

相关文章