我已经完成了一些编程和一些SQL但除了我自己的小项目之外没有开发人员。 我现在有一个问题,我想在纯SQL中解决,但无法弄清楚如何。 我有2个简单的表格,我需要绘制月度报告,但我需要做一些计数,这是棘手的部分。 这是结构...
import sys
import cv2
from PyQt5.QtCore import QThread, pyqtSignal, Qt
from PyQt5.QtGui import QPixmap, QImage
from PyQt5.QtWidgets import QApplication, QWidget, QLabel
import datetime
class App(QWidget):
def __init__(self):
super().__init__()
self.title = 'PyQt5 Video'
self.left = 100
self.top = 100
self.width = 640
self.height = 480
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
self.resize(1800, 1200)
# create a label
# create a label
label = QLabel(self)
label.move(280, 120)
label.resize(640, 480)
label1 = QLabel(self)
label1.move(580, 620)
self.th = Thread(self)
self.th.changePixmap.connect(label.setPixmap)
self.th.changeLabel.connect(label1.setText)
self.th.start()
def closeEvent(self, event):
self.th.stop()
QWidget.closeEvent(self, event)
class Thread(QThread):
changePixmap = pyqtSignal(QPixmap)
changeLabel = pyqtSignal(str)
def __init__(self, parent=None):
QThread.__init__(self, parent=parent)
self.isRunning = True
def run(self):
cap = cv2.VideoCapture(0)
while self.isRunning:
ret, frame = cap.read()
rgbImage = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
convertToQtFormat = QImage(rgbImage.data, rgbImage.shape[1], rgbImage.shape[0], QImage.Format_RGB888)
convertToQtFormat = QPixmap.fromImage(convertToQtFormat)
p = convertToQtFormat.scaled(640, 480, Qt.KeepAspectRatio)
self.changePixmap.emit(p)
now = datetime.datetime.now()
sec = now.second
self.changeLabel.emit(str(sec))
def stop(self):
self.isRunning = False
self.quit()
self.wait()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
ex.show()
sys.exit(app.exec_())
这些规则让我觉得太复杂了......
下面没有total_trips的示例我可以使用此声明。
var sum = File.ReadLines(patch + label97.Text + ".ext")
.Where(l =>!l.StartsWith("1"))
.Sum(l => int.Parse(l.Split(',')[11]);
想要样本日期输出
table
km_locations
columns
location_id INT
location_name TXT
table
km_trips
colums
trip_id INT
trip_date DATE
start_location_id INT
end_location_id INT
km_start INT
km_end INT
对于SQL语句来说可能太多了,但我认为可能有视图,工会和som疯狂技能。 这是一个我从Excel迁移的新项目,因此我对可以使这项工作的表结构提出任何建议。 现在我正在尝试使用SQLite进行此工作,但如果这是我唯一的选择,将使用另一个数据库。
感谢。
答案 0 :(得分:0)
尝试相关的子查询类型
SELECT
t.trip_date,
c1.location_name AS 'trip_start',
c2.location_name AS 'trip_end',
t.km_start,
t.km_end,
(SELECT count(DISTINCT t2.trip_date) cnt
FROM km_trips t2
WHERE t2.trip_date < t.trip_date
AND t2.start_location_id = t.start_location_id
AND t2.end_location_id = t.end_location_id
AND (SELECT location_id FROM km_locations WHERE location_name = 'home')
IN (t2.start_location_id, t2.end_location_id)
) count
FROM km_trips t
LEFT JOIN km_locations c1 ON c1.location_id = t.start_location_id
LEFT JOIN km_locations c2 ON c2.location_id = t.end_location_id
WHERE t.trip_date BETWEEN '2016-02-06' AND '2016-03-10'
ORDER BY t.trip_date ASC, t.km_start ASC