结合这两个陈述 [英] Combine these 2 statements

查看:104
本文介绍了结合这两个陈述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我尝试合并2个语句,但第一个选项受第二个结果限制。如果最后一个陈述是真的,我不希望'12'成为下拉菜单中的可用选项。





1)选择payment_plan.payment_plan_cde,payment_plan.pay_plan_desc

来自payment_plan

其中payment_plan.payment_plan_cde in('TF','12')







2)SELECT student_term_sum.hrs_enrolled

FROM student_term_sum

WHERE student_term_sum。 id_num = @@ HostID和student_term_sum.yr_cde ='2018'和student_term_sum.trm_cde = '20'和student_term_sum.hrs_enrolled> 0



我尝试了什么:



我还没试过到目前为止的任何组合,但我对复杂的SQL并不是很好,所以我想我最好找一点帮助。

Hello, I am try to combine 2 statements but have the first one's options limited by the second ones results. If the last statement is true I don't want '12' to be an available option in the drop down.


1) SELECT payment_plan.payment_plan_cde, payment_plan.pay_plan_desc
FROM payment_plan
Where payment_plan.payment_plan_cde in ('TF','12')

and

2) SELECT student_term_sum.hrs_enrolled
FROM student_term_sum
WHERE student_term_sum.id_num = @@HostID and student_term_sum.yr_cde = '2018' AND student_term_sum.trm_cde = '20' and student_term_sum.hrs_enrolled > 0

What I have tried:

I haven't tried any combination as of yet but I am not very good with complex SQL so I figured I better reach out for a little help.

推荐答案

因为你的发送查询只返回一个单个字段(可能有很多值?),请查看子查询 [ ^ ]的表述如下:
Since your send query only returns a single field (possibly with many values?), look into subquery[^] formulated much like below:
SELECT * FROM Table1 WHERE field1 NOT IN (SELECT field2 FROM table 2)

这有变化,并且在适当的条件下(仅从单个字段返回单个值)它们也可以在你的SELECT中。



倾斜更多的SQL并且写起来更容易: 某些任务非常有用,它们被用作语言特征。

There are variations on this and, under appropriate conditions (only return a single value from a single field) they can be in your SELECT as well.

Leaning more SQL and it gets easier to write:   Certain tasks were so useful they were made into language features.


这篇关于结合这两个陈述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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