SQL:如何选择列的特定不同值 [英] SQL: How to select the particular distinct value of a column

查看:85
本文介绍了SQL:如何选择列的特定不同值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我需要其他字段的值对应于不同的registrationno,但distict属性不应应用于其他字段

这是我的代码:


Hello,


i need the values of the other fields corresponding to distinct registrationno ,but the distict property should not be applied to the other fields

Here is my code:


select  'Active' as VS, registrationno, gps_datetime,speed,location  from gpsdata_previous   
where registrationno in(select registrationno from  vehicle_superuser where superuserid=@uid) AND(GPS_DATETIME BETWEEN @fromdate AND @todate)   
and   speed <>0 

union   
  
select 'Inactive' as VS,registrationno,gps_datetime,speed,location  from gpsdata_previous   
  
where registrationno in(select registrationno from  vehicle_superuser where superuserid=@uid)  AND(GPS_DATETIME BETWEEN @fromdate AND @todate)  
and  speed=0 




请帮帮我.

谢谢.




Please help me out.

Thanks.

推荐答案

只需从选择查询中删除所有其他字段,然后在registration_no上单独应用.
Just remove all other fields from your select query and apply distinct on the registration_no.


这篇关于SQL:如何选择列的特定不同值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆