如何编写带有涉及第二张表的条件的SQL查询? [英] How do I Write a SQL Query With a Condition Involving a Second Table?

查看:79
本文介绍了如何编写带有涉及第二张表的条件的SQL查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

表1

...

LogEntryID * PrimaryKey *



ThresholdID---链接到应用于此日志条目的适当阈值。

...

Table1
...
LogEntryID *PrimaryKey*
Value
ThresholdID - - - Link to the appropriate threshold being applied to this log entry.
...

Table2

...

ThresholdID * PrimaryKey *

阈值

...

Table2
...
ThresholdID *PrimaryKey*
Threshold
...

所有字段均为整数。

那里的 ...事物表明这些表所包含的信息远不止于此。设置它们的方式是有原因的,目前我无法更改。

All fields are integers.
The "..." thingies are there to show that these tables hold a lot more imformation than just this. They are set up this way for a reason, and I can't change it at this point.

我需要编写一条SQL语句从 Table1 中选择每条记录,其中该特定日志记录中的值字段小于 Table2 的链接记录中的阈值字段。

I need write a SQL statement to select every record from Table1 where the Value field in that particular log record is less than the Threshold field in the linked record of Table2.

我刚接触SQL,所以我知道这是一个基本问题。

如果有人可以告诉我该SQL语句的结构

I'm newish to SQL, so I know this is a basic question.
If anyone can show me how this SQL statement would be structured, it would be greatly appreciated.

推荐答案

SELECT T1.*
  FROM Table1 T1
  JOIN Table2 T2 ON T2.ThresholdID = T1.ThresholdID
 WHERE T2.Threshold > T1.Value

这篇关于如何编写带有涉及第二张表的条件的SQL查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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