如何使用SQL查询在不同的行中打印结果?

编程入门 行业动态 更新时间:2024-10-27 10:27:31
本文介绍了如何使用SQL查询在不同的行中打印结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在执行以下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查询在不同的行中打印结果?

本文发布于:2023-10-20 22:17:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1512299.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!