SQL Server:删除可交换列中的重复项

时间:2019-01-19 17:19:06

标签: sql sql-server join select

我有这个查询:

select 
    OSFES97.CodeId, OSFBA97.CodeId, OSFES97.ReceiveDate
from 
    StockArchives OSFES97 
inner join 
    StockArchives OSFBA97 on OSFBA97.ReceiveDate = OSFES97.ReceiveDate
where 
    OSFES97.CodeId <> OSFBA97.CodeId 

它返回如下结果:

CodeId    CodeId    ReceiveDate
------------------------------------------
1         2         2019-01-13 15:55:20.537
2         1         2019-01-13 15:55:20.537
1         2         2019-01-13 15:55:30.537
2         1         2019-01-13 15:55:30.537

由于以下供我使用的记录被视为重复记录(如果它们具有相同的ReceiveDate),我想删除其中一个并实现此结果:

CodeId    CodeId    ReceiveDate
------------------------------------------
1         2         2019-01-13 15:55:20.537
1         2         2019-01-13 15:55:30.537

1 个答案:

答案 0 :(得分:3)

使用import sys import cv2 import numpy as np import imutils from PyQt5 import QtCore from PyQt5.QtCore import Qt, QTimer from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout, QVBoxLayout, QLCDNumber, QSlider, QLabel, QCheckBox from PyQt5.QtGui import QPixmap, QImage class MyWindow(QWidget): def __init__(self): super().__init__() self.imglabel = QLabel(self) self.imglabel.setFixedSize(1200, 900) ori_img = cv2.imread("../resources/omr-1-ans-ori.png", cv2.IMREAD_COLOR) ori_img = imutils.resize(ori_img, height=960) self.gray_img = cv2.cvtColor(ori_img, cv2.COLOR_BGR2GRAY) self.gray_img_c = ori_img self.thresh = False self.thresh_karnel_size = 11 self.init_ui() def init_ui(self): # lcd = QLCDNumber(self) hbox1 = QHBoxLayout() cb_thresh = QCheckBox('thresh', self) cb_thresh.setChecked(False) cb_thresh.stateChanged.connect(self.changeTitleThresh) hbox1.addWidget(cb_thresh) thresh_slider = QSlider(Qt.Horizontal, self) thresh_slider.setFocusPolicy(Qt.StrongFocus) thresh_slider.setTickPosition(QSlider.TicksBothSides) thresh_slider.setTickInterval(1) thresh_slider.setSingleStep(1) thresh_slider.setPageStep(1) thresh_slider.setMinimum(1) thresh_slider.setMaximum(127) thresh_slider.valueChanged[int].connect(self.threshSliderChangeValue) vbox = QVBoxLayout() vbox.addLayout(hbox1) vbox.addWidget(thresh_slider) vbox.addWidget(self.imglabel) self.setLayout(vbox) self.setGeometry(50, 50, 1200, 768) self.setWindowTitle('Learning PyQT5') self.updateImage() self.show() def changeTitleThresh(self, state): # print("thresh checkbox: ", state, Qt.Checked) if state == Qt.Checked: self.thresh = True else: self.thresh = False def threshSliderChangeValue(self, value): ksize = (value * 2) + 1 print("ksize: ", ksize) if ksize > 1 and ksize % 2 != 0 and self.thresh: self.thresh_karnel_size = ksize self.gray_img = cv2.threshold(self.gray_img, self.thresh_karnel_size, 255, cv2.THRESH_BINARY)[1] self.gray_img_c = cv2.cvtColor(self.gray_img.copy(), cv2.COLOR_GRAY2BGR) self.updateImage() def updateImage(self): height, width, channel = self.gray_img_c.shape bytesPerLine = 3 * width qImg = QImage(self.gray_img_c.data, width, height, bytesPerLine, QImage.Format_RGB888) pixMap = QPixmap.fromImage(qImg) pixMap = pixMap.scaled(700, 500, Qt.KeepAspectRatio) self.imglabel.setPixmap(pixMap) self.imglabel.show() if __name__ == '__main__': app = QApplication(sys.argv) ex = MyWindow() sys.exit(app.exec_()) 运算符将创建这些(逻辑)重复项。相反,您可以决定要使用哪个ID较低的列,并相应地使用<><。例如:

>