在case语句中如何处理多于1行 [英] how do handle more than 1 rows , in case statement
本文介绍了在case语句中如何处理多于1行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
选择 E.KeyBatchClass,
(案例 当 E.InternalTest = ' False' 然后(从 BachClasses中选择 BC.ClassName BC 其中 B.Key_Batch = BC.Key_Batch)
当 E.InternalTest = ' True' 然后(选择 BC.ClassName 来自 BachClasses BC 其中 B.Key_Batch = 7) - 我的这一行返回超过1行,我需要相同的结果。即想要多行当E.InteralTest =真
结束) Batch_Class
来自考试E,批量B
其中 E.keyBatch = B.key_Batch
和 E.KeyExam = 3
和 E.keyBatch = 7
错误子查询返回的值超过1。当子查询遵循=,!=,<,< =,>,> =或子查询用作表达式时,不允许这样做。
解决方案
检查这个
选择
E. KeyBatchClass,
BC.ClassName as Batch_Class
来自考试E
加入批次B 开启 E.keyBatch = B.key_Batch
JOIN BachClasses 开启 B.Key_Batch =
(案例 当 E.InternalTest = ' False' 然后 BC.Key_Batch else 7 结束)
其中
E.KeyExam = 3 和 E.keyBatch = 7
Select E.KeyBatchClass,
(Case When E.InternalTest='False' Then (Select BC.ClassName from BachClasses BC where B.Key_Batch=BC.Key_Batch)
When E.InternalTest='True' Then (Select BC.ClassName from BachClasses BC where B.Key_Batch=7) --My this line returns more than 1 rows and i need the same, result. i.e want multiple rows When E.InteralTest=True
End) as Batch_Class
from Exam E,Batch B
where E.keyBatch=B.key_Batch
and E.KeyExam=3
and E.keyBatch=7
Error Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
解决方案
Check this
Select E.KeyBatchClass, BC.ClassName as Batch_Class from Exam E Join Batch B On E.keyBatch=B.key_Batch JOIN BachClasses On B.Key_Batch= (Case When E.InternalTest='False' Then BC.Key_Batch else 7 end) where E.KeyExam=3 and E.keyBatch=7
这篇关于在case语句中如何处理多于1行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文