如何使用SQL查询在不同的行中打印结果? [英] How to print the result in different line using SQL query?
问题描述
我正在执行以下SQL查询,其结果显示为一行,但我不想将其打印为一行,而是想分成两行并打印值.
I am executing the below SQL query which result is displaying as in one line but instead of printing it it one line i want to split into two different line and print the value.
SQL查询:
select
(case when max(PK_MTF1000) = min(PK_MTF1000) and count(PK_MTF1000) = count(*) or max(PK_MTF1000) is null then 'same' else 'diff'end)as PK_MTF1000,max(PK_MTF1000),min(PK_MTF1000) + CHAR(13) ,
(case when max(MID) = min(MID) and count(MID) = count(*) or max(MID) is null then 'same' else 'diff'end) as MID,max(MID),min(MID)
from MTF1000 where ORG=' BULGER CAPITAL LLC';
输出:
same NULL NULL diff 1962008204906400 1962008204823K00
期望输出分成两行,并按如下所示打印输出
Expecting Output split into two different line and print the output as below
same NULL NULL
diff 1962008204906400 1962008204823K00
尝试使用CHAR(13)
Tried with CHAR(13)
select
(case when max(PK_MTF1000) = min(PK_MTF1000) and count(PK_MTF1000) = count(*) or max(PK_MTF1000) is null then 'same' else 'diff'end)as PK_MTF1000,max(PK_MTF1000),min(PK_MTF1000) + CHAR(13) + --<--,
(case when max(MID) = min(MID) and count(MID) = count(*) or max(MID) is null then 'same' else 'diff'end) as MID,max(MID),min(MID)
from MTF1000 where ORG=' BULGER CAPITAL LLC';
获取错误为:
-ORA-00936:缺少表达式
00936. 00000-缺少表达式"
*原因:
*动作:
第2行的错误:189列
-ORA-00936: missing expression
00936. 00000 - "missing expression"
*Cause:
*Action:
Error at Line: 2 Column: 189
有什么方法可以分成两行吗?
Is there any way to split into two line?
推荐答案
我认为您可能想要一个UNION,因此每组数据都有自己的行.
I think you probably want a UNION, so each set of data has its own row.
select
(case when max(PK_MTF1000) = min(PK_MTF1000) and count(PK_MTF1000) = count(*) or max(PK_MTF1000) is null then 'same' else 'diff'end)as PK_MTF1000,
max(PK_MTF1000),
min(PK_MTF1000)
from MTF1000 where ORG=' BULGER CAPITAL LLC'
union all
select
(case when max(MID) = min(MID) and count(MID) = count(*) or max(MID) is null then 'same' else 'diff'end) as MID,
max(MID),
min(MID)
from MTF1000 where ORG=' BULGER CAPITAL LLC';
这篇关于如何使用SQL查询在不同的行中打印结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!