将两个sql查询组合成一个查询 [英] Combine two sql queries into one query
本文介绍了将两个sql查询组合成一个查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何组合以下2个查询,以便我可以获得两列PAYMODE
和PAYTYPE。这两个查询都是相似的,同样的表。将两个sql查询组合成一个查询,以便我不需要执行两个单独的查询。
How can I combine following 2 queries so that I can get two columns PAYMODE and PAYTYPE. Both queries are similar and for same table.Combine two sql queries into one query so that I don't need to execute two separate queries.
SELECT ETBL_DESC_TXT as PAYMODE
FROM tedit
WHERE CO_ID = 'CP'
AND ETBL_TYP_ID = 'PMODE'
AND ETBL_VALU_ID = 'RC'
select ETBL_DESC_TXT as PAYTYPE
FROM tedit
WHERE CO_ID = 'CP'
AND ETBL_TYP_ID = 'PTYPE'
AND ETBL_VALU_ID = 'ER'
推荐答案
由于记录显示在源数据的不同行中,我将很难在单个结果行中检索它们。您可以在单个查询中获取结果,为您提供两行。尝试这样:
Since the records appear in different rows of the source data, I will be difficult to retrieve them in a single result row. You can get the results in a single query that gives you two rows. Try this:
SELECT ETBL_DESC_TXT as PAYFIELD
FROM tedit
WHERE CO_ID = 'CP' AND (
(ETBL_TYP_ID = 'PMODE' AND ETBL_VALU_ID = 'RC')
OR (ETBL_TYP_ID = 'PTYPE' AND ETBL_VALU_ID = 'ER')
)
ORDER BY ETBL_TYP_ID
第一行将包含付费模式,第二行将包含paytype。
The first row will contain the paymode, and the second row will contain the paytype.
这篇关于将两个sql查询组合成一个查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文