检索唯一记录SQL

时间:2018-08-02 14:54:50

标签: sql sql-server tsql

我有一个表UNIQUES,如:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.19.1/moment-with-locales.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-material-datetimepicker/2.7.1/js/bootstrap-material-datetimepicker.js"></script>

<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-material-design/0.5.10/css/bootstrap-material-design.min.css" rel="stylesheet"/>

<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

<div class="form-line">
   <input type="text" class="form-control datepicker"  name="tarih" placeholder="gg/aa/yyyy" />
</div>

我想获得“数字”字段没有重复或不重复的唯一记录。

预期结果:

ID        DESC      DATE         NUMBER        Amount
100       TEST1     01-01-18     1009674       10.20 
100       TEST2     01-02-18     1009674       245.10
100       TEST3     01-03-18     1009942       156.000  
100       TEST4     02-14-18     00042EX       154.6
100       TEST5     04-15-18     00042EX       25.10
100       TEST6     05-20-18     1011055       1564.0

我正在使用的查询:

ID      DESC      DATE          NUMBER         AMOUNT
100     TEST3     01-03-18      1009942        156.000 
100     TEST6     05-20-18      1011055        1564.0 

任何帮助或帮助都将不胜感激。

5 个答案:

答案 0 :(得分:3)

我认为你很亲近

tensorflow.python.framework.errors_impl.InvalidArgumentError: Expected size[0] in [0, 100], but got 508
     [[Node: Slice_4 = Slice[Index=DT_INT32, T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"](unstack_2, PadOrClipBoxList/zeros_1, stack_4)]]
     [[Node: gradients/FirstStageFeatureExtractor/resnet_v1_50/resnet_v1_50/block3/unit_6/bottleneck_v1/conv3/Conv2D_grad/Conv2DBackpropInput/_7800 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_4351_...kpropInput", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

你想要的

SELECT * FROM UNIQUES 
WHERE NUMBER IN (SELECT NUMBER FROM 
UNIQUES GROUP BY NUMBER HAVING COUNT(NUMBER)=1)

我的回答是:

enter image description here

有几种不错的方法,我只是根据问题简单地将其从ID DESC DATE NUMBER AMOUNT 100 TEST3 01-03-18 1009942 156.000 100 TEST6 05-20-18 1011055 1564.0 更改为NOT IN

答案 1 :(得分:2)

您可以使用if sql_version == '1': # SSMS 2008 path = '' # which value to use? elif sql_version == '2': # SSMS 2014 print (sql_version)

subquery

答案 2 :(得分:2)

我只使用窗口功能:

select u.*
from (select u.*, count(*) over (partition by number) as cnt
      from uniques u
     ) u
where cnt = 1;

答案 3 :(得分:1)

myGO.GetComponent<MeshRenderer>().enabled = false;

我会避免使用列名,例如DESC,DATE和NUMBER,因为它们出现在SQL和ODBC保留字列表中。

答案 4 :(得分:0)

除了not exists方法之外,您还可以outer join表本身,并检查“重复”表中是否为空。

select *
from
    uniques u
    left outer join uniques dup
        on (u.NUMBER=dup.NUMBER)
where
    dup.NUMBER is null

之所以有用,是因为左外部联接将从“左”表返回所有内容(别名为上述u),并且将从“右”表返回null值(别名为{ {1}}),如果没有符合dup条件的行。