简体   繁体   English

比较两个不同表中的列

[英]comparing columns in two different tables

I am using C#, MySQL to monitor some fuel tanks I'm currently using a function to monitor the tanks that assigns one of three statuses to each tank (good, warning, critical). 我正在使用C#,MySQL监视某些燃料箱,而我目前正在使用一种功能来监视对每个燃料箱分配三种状态(良好,警告,严重)中的一种的燃料箱。

One of the things this program has to do is send an email when the tank status changes. 该程序必须做的一件事是在储罐状态发生变化时发送电子邮件。 What I need help with is how to compare the tank status from 2 different table to determine if the status has changed. 我需要帮助的是如何比较2个不同表中的储罐状态,以确定状态是否已更改。

Here are the two tables I'm using: 这是我正在使用的两个表:

tank table 坦克表

tank_number INT,
station_id int, 
ip_address varchar(30),
product varchar(30),
alert_level1 int,
alert_level2 int, 
gallons int,
date,
status

status table 状态表

ip_address varchar(30),
status varchar(5),
gallons int,
tank_number int,
date

This should just be a simple join on the two tables. 这应该只是两个表的简单连接。 Something along the lines of: 类似于以下内容:

SELECT s.status ,
       t.tank_number
  FROM status s INNER JOIN tank t ON s.tank_number = t.tank_number
 WHERE s.status <> t.status

This assumes that tank_number is a unique identifier for the tank and retrieves just those tanks whose status has changed. 假设tank_number是战车的唯一标识符,并且仅检索状态已更改的战车。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM