比较两个不同表中的列 [英] comparing columns in two different tables

查看:52
本文介绍了比较两个不同表中的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 C#、MySQL 来监控一些油箱我目前正在使用一个函数来监控油箱,该函数为每个油箱分配三种状态之一(良好、警告、严重).

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).

该程序必须做的一件事是在储罐状态发生变化时发送电子邮件.我需要帮助的是如何比较 2 个不同表中的油箱状态以确定状态是否已更改.

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.

这是我使用的两个表:

坦克桌

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

状态表

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

这假设 tank_number 是坦克的唯一标识符,并且仅检索状态已更改的那些坦克.

This assumes that tank_number is a unique identifier for the tank and retrieves just those tanks whose status has changed.

这篇关于比较两个不同表中的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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