使用缩进查询输出 [英] Query output with indentation

查看:51
本文介绍了使用缩进查询输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有表System


component | subcomponent  (foreign key with subsystem table)
----------+-------------
cpu       |  1
monitor   |
lcd       |
keybord   |
mouse     |

子组件表


id  | name
----+-------------
1   | motherboard
1   | harddisk
1   | cdrom

现在我要打印带有缩进

所需的输出


cpu
   --motherboar
   --harddisk
   --cdrom
keyboard
mouse
lcd

怎么可能?

推荐答案

可以使用例如左联接和一些字符串格式设置功能:

It's possible using e.g. a left join and some of the string formatting functions:

select ... as parent, '  -- ' || coalesce(..., '') as child
from ... left join ... on ...

您也可以合并东西,等等,以获取所需的内容。

You could also union things instead, etc. to get exactly what you requested.

正如已经建议的那样,将其保留在视图之外。

BUT you really ought to leave that up to the view, as already suggested.

这篇关于使用缩进查询输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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