`
deepfuture
  • 浏览: 4375394 次
  • 性别: Icon_minigender_1
  • 来自: 湛江
博客专栏
073ec2a9-85b7-3ebf-a3bb-c6361e6c6f64
SQLite源码剖析
浏览量:79860
1591c4b8-62f1-3d3e-9551-25c77465da96
WIN32汇编语言学习应用...
浏览量:69450
F5390db6-59dd-338f-ba18-4e93943ff06a
神奇的perl
浏览量:102784
Dac44363-8a80-3836-99aa-f7b7780fa6e2
lucene等搜索引擎解析...
浏览量:283926
Ec49a563-4109-3c69-9c83-8f6d068ba113
深入lucene3.5源码...
浏览量:14910
9b99bfc2-19c2-3346-9100-7f8879c731ce
VB.NET并行与分布式编...
浏览量:66977
B1db2af3-06b3-35bb-ac08-59ff2d1324b4
silverlight 5...
浏览量:31807
4a56b548-ab3d-35af-a984-e0781d142c23
算法下午茶系列
浏览量:45791
社区版块
存档分类
最新评论

postgresql-从子查询中构造数组

阅读更多

声明:本PostgreSQl实用指南系列为刘兴(http://deepfuture.iteye.com/)原创,未经笔者授权,任何人和机构不能转载

子查询的结果中构造一个数组

D:\pgsql>psql mydb
psql (8.4.2)
Type "help" for help.

mydb=#
mydb=# select * from student,citys where student.city=citys.id
mydb-# ;
    name    | age | city |  sex  | name | id
------------+-----+------+-------+------+----
 艾丝凡     |  18 |    3 |       | 上海 |  3
 萨芬       |  19 |    3 |       | 上海 |  3
 未来       |  20 |    2 | man   | 湛江 |  2
 干哈       |  18 |    2 | man   | 湛江 |  2
 deepfuture |  20 |    1 | woman | 长沙 |  1
 张三       |  21 |    1 | woman | 长沙 |  1
 王五       |  25 |    3 | man   | 上海 |  3
 李白       |  23 |    2 | man   | 湛江 |  2
 李国       |  24 |    1 | woman | 长沙 |  1
(9 rows)

 


mydb=# select citys.name as 城市,array(select name from student where student.ci
ty=citys.id) as 学生 from citys;
 城市 |          学生
------+------------------------
 长沙 | {deepfuture,张三,李国}
 湛江 | {未来,干哈,李白}
 上海 | {艾丝凡,萨芬,王五}
(3 rows)


mydb=# select * from student;
    name    | age | city |  sex
------------+-----+------+-------
 艾丝凡     |  18 |    3 |
 萨芬       |  19 |    3 |
 未来       |  20 |    2 | man
 干哈       |  18 |    2 | man
 deepfuture |  20 |    1 | woman
 张三       |  21 |    1 | woman
 王五       |  25 |    3 | man
 李白       |  23 |    2 | man
 李国       |  24 |    1 | woman
(9 rows)


mydb=# select * from citys;
 name | id
------+----
 长沙 |  1
 湛江 |  2
 上海 |  3
(3 rows)


mydb=#

 

0
0
分享到:
评论

相关推荐

    postgresql-42.2.2.jar+postgresql-9.2-1003.jdbc4.jar

    标题中提到的"postgresql-42.2.2.jar"和"postgresql-9.2-1003.jdbc4.jar"是与PostgreSQL相关的Java档案(JAR)文件,它们在Java应用程序中用于与PostgreSQL数据库进行交互。 首先,"postgresql-42.2.2.jar"是...

    postgresql-42.2.6-API文档-中文版.zip

    赠送jar包:postgresql-42.2.6.jar; 赠送原API文档:postgresql-42.2.6-javadoc.jar; 赠送源代码:postgresql-42.2.6-sources.jar; 赠送Maven依赖信息文件:postgresql-42.2.6.pom; 包含翻译后的API文档:...

    postgresql-13.2-1-windows-x64.rar

    postgresql-13.2-1-windows-x64.rar postgresql-13.2-1-windows-x64.rar postgresql-13.2-1-windows-x64.rar postgresql-13.2-1-windows-x64.rar postgresql-13.2-1-windows-x64.rar

    postgresql-42.2.5-API文档-中英对照版.zip

    赠送jar包:postgresql-42.2.5.jar; 赠送原API文档:postgresql-42.2.5-javadoc.jar; 赠送源代码:postgresql-42.2.5-sources.jar; 赠送Maven依赖信息文件:postgresql-42.2.5.pom; 包含翻译后的API文档:...

    postgresql-42.5.0.jar

    postgresql-42.5.0.jar在许多Java框架如Hibernate和Spring等中使用,并很受开发人员的欢迎。它是经过定期更新和改进的,以确保其与最新版本的PostgreSQL数据库兼容,同时提供了丰富的API和文档,方便程序员进行开发...

    postgresql-42.3.3-API文档-中文版.zip

    赠送jar包:postgresql-42.3.3.jar; 赠送原API文档:postgresql-42.3.3-javadoc.jar; 赠送源代码:postgresql-42.3.3-sources.jar; 赠送Maven依赖信息文件:postgresql-42.3.3.pom; 包含翻译后的API文档:...

    postgresql-42.2.2-API文档-中文版.zip

    赠送jar包:postgresql-42.2.2.jar; 赠送原API文档:postgresql-42.2.2-javadoc.jar; 赠送源代码:postgresql-42.2.2-sources.jar; 赠送Maven依赖信息文件:postgresql-42.2.2.pom; 包含翻译后的API文档:...

    PostgreSQL(postgresql-13.5-1-windows-x64.exe)

    PostgreSQL(postgresql-13.5-1-windows-x64.exe)适用于Windows x86-64 PostgreSQL是一种特性非常齐全的自由软件的对象-关系型数据库管理系统(ORDBMS),是以加州大学计算机系开发的POSTGRES,4.2版本为基础的...

    postgresql-42.3.3.jar

    `postgresql-42.3.3.jar` 提供了对PostgreSQL的JDBC驱动实现,使得Java开发者可以利用JDBC API来执行诸如建立数据库连接、执行SQL查询、处理结果集等任务。 在使用`postgresql-42.3.3.jar`之前,你需要将其添加到你...

    PostgreSQL(postgresql-14.2-2-windows-x64.exe)

    PostgreSQL(postgresql-14.2-2-windows-x64.exe),适用于Windows系统:PostgreSQL是一种特性非常齐全的自由软件的对象-关系型数据库管理系统(ORDBMS),是以加州大学计算机系开发的POSTGRES,4.2版本为基础的对象...

    postgresql-12.18-1-windows-x64.exe

    postgresql-12.18-1-windows-x64.exe

    postgresql-9.1.3-1-windows-x64

    此“postgresql-9.1.3-1-windows-x64”压缩包是专为64位Windows系统设计的PostgreSQL 9.1.3版本。 PostgreSQL 9.1.3是该数据库系统的其中一个稳定版本,发布于2012年,包含了多项增强和修复。在这一版本中,开发者...

    PostgreSQL-9.2.4-1-windows-x64.rar

    首先,"PostgreSQL-9.2.4-1-windows-x64.rar" 是一个压缩文件,包含了PostgreSQL 9.2.4在64位Windows操作系统上的安装程序。解压这个RAR文件后,我们会得到"PostgreSQL-9.2.4-1-windows-x64.exe",这是用于安装...

    postgresql-42.2.5

    postgresql-42.2.5 JBDC驱动,这个驱动可以用于Pycharm连接到PostgreSQL,具体操作方法可以阅读《Pycharm 配置PostgreSQL-利用自带database》网址:...

    postgresql-10.16-2-windows-x64.zip

    此压缩包"postgresql-10.16-2-windows-x64.zip"包含了PostgreSQL 10.16的64位Windows版本,适合在Windows操作系统上搭建数据库服务。 PostgreSQL 10.16是该数据库系统的一个稳定版本,它在前一版本的基础上进行了多...

    postgresql-42.3.1-API文档-中文版.zip

    赠送jar包:postgresql-42.3.1.jar; 赠送原API文档:postgresql-42.3.1-javadoc.jar; 赠送源代码:postgresql-42.3.1-sources.jar; 赠送Maven依赖信息文件:postgresql-42.3.1.pom; 包含翻译后的API文档:...

    postgresql-10.21-1-windows-x64.exe安装包

    postgresql-10.21-1-windows-x64.exe安装包

    postgresql-10.23-1-windows32版本

    postgresql-10.23-1的windows32版本

    postgresql-9.2.24-1.el7_5.x86_64

    postgresql-9.2.24-1.el7_5.x86_64,postgresql-libs-9.2.24-1.el7_5.x86_64.rpm,postgresql-devel-9.2.24-1.el7_5.x86_64.rpm

    PostgreSQL(postgresql-13.5.tar.gz)

    PostgreSQL(postgresql-13.5.tar.gz) PostgreSQL是一种特性非常齐全的自由软件的对象-关系型数据库管理系统(ORDBMS),是以加州大学计算机系开发的POSTGRES,4.2版本为基础的对象关系型数据库管理系统。POSTGRES...

Global site tag (gtag.js) - Google Analytics