将两个sql查询合并为一个查询 [英] Combine two sql queries into one query

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

问题描述

如何组合以下 2 个查询,以便获得两列 PAYMODE和支付类型.这两个查询是相似的,并且是针对同一张表的.将两个 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

第一行包含支付模式,第二行包含支付类型.

The first row will contain the paymode, and the second row will contain the paytype.

这篇关于将两个sql查询合并为一个查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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