GVKun编程网logo

如何通过PostgreSQL中的组合来计算并发事件的频率/数量?

82

在本文中,您将会了解到关于如何通过PostgreSQL中的组合来计算并发事件的频率/数量?的新资讯,并给出一些关于centos7下源码编译安装php支持PostgreSQLpostgresql手册po

在本文中,您将会了解到关于如何通过PostgreSQL中的组合来计算并发事件的频率/数量?的新资讯,并给出一些关于centos 7下源码编译安装php支持PostgreSQL postgresql手册 postgresql官网下载 postgresql视频教、Postgres 中的组合 SQL 计数查询、postgresql – Heroku – 无法通过Play Framework应用程序设置postgres数据库?、postgresql – Postgres中字符串的单词频率?的实用技巧。

本文目录一览:

如何通过PostgreSQL中的组合来计算并发事件的频率/数量?

如何通过PostgreSQL中的组合来计算并发事件的频率/数量?

在MySQL中考虑以下内容(您的DBFiddle指向该位置):


    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine($"Main Thread: {Thread.CurrentThread.ManagedThreadId} Started");


            Task task1 = Task.Run(() =>
            {
                PrintCounter();
            });
            task1.Wait();
            Console.WriteLine($"Main Thread: {Thread.CurrentThread.ManagedThreadId} Completed");
            Console.ReadKey();

        }
        static void PrintCounter()
        {
            Console.WriteLine($"Cild Thread: {Thread.CurrentThread.ManagedThreadId} Started");
            for (int count = 1; count <=5; count++)
            {
                Console.WriteLine($"Count: {count}");
            }
            Console.WriteLine($"Cild Thread: {Thread.CurrentThread.ManagedThreadId} Completed");
        }
    }
}

在PostgreSQL中等效:

SELECT name,COUNT(*)
FROM (
    SELECT group_concat(name ORDER BY name) name
    FROM mytable
    GROUP BY startts,endts
    ORDER BY name
) as names
GROUP BY name
ORDER BY name

首先,在并发事件(在子查询中)中创建一个列表,然后对它们进行计数。

centos 7下源码编译安装php支持PostgreSQL postgresql手册 postgresql官网下载 postgresql视频教

centos 7下源码编译安装php支持PostgreSQL postgresql手册 postgresql官网下载 postgresql视频教

1. 下载源码

$ mkdir /usr/downloads
$ wget -c http://cn2.php.net/distributions/php-5.6.20.tar.gz
$ tar -xvf php-5.6.20.tar.gz
$ mv php-5.6.20 /usr/local/src
$ cd !$ &amp; cd php-5.6.20
登录后复制

2. 阅读安装指导

$ ls -also
$ less README
$ less INSTALL
登录后复制

3. 安装依赖包

$ yum install apr apr-util apr-devel apr-util-devel prce lynx
登录后复制

4. 安装httpd

$ wget -c http://apache.fayea.com//httpd/httpd-2.4.20.tar.gz
$ tar -xvf httpd-2.4.20.tar.gz
$ cd httpd-2.4.20
$ ./configure \
--prefix=/usr/local/programs/apache2 \
--enable-rewrite \
--enable-so \
--enable-headers \
--enable-expires \
--with-mpm=worker \
--enable-modules=most \
--enable-deflate \
--enable-module=shared
$ make
$ make install
$ cd /usr/local/programs/apache2
$ cp bin/apachectl /etc/init.d/httpd ## 复制启动脚本
$ /etc/init.d/httpd start ## 启动apache服务器,访问http://localhost/
$ egrep -v ''^[ ]*#|^$'' /usr/local/apache2/conf/httpd.conf | nl ## 查看apache服务器的配置
## 将apache加入系统服务
vi /etc/rc.d/rc.local
```
/usr/local/programs/apache2/bin/apachectl start
```
$ cat /etc/rc.local
登录后复制

4. 安装postgresql

立即学习“PHP免费学习笔记(深入)”;

$ yum install readline-devel  ## 安装readline依赖
$ cd /usr/downloads
$ wget -c https://ftp.postgresql.org/pub/source/v9.5.0/postgresql-9.5.0.tar.bz2
$ tar -xvf postgresql-9.5.0.tar.bz2
$ cd postgresql-9.5.0
$ ./configure --prefix=/usr/local/programs/postgresql
$ make
$ su
$ make install
$ /sbin/ldconfig /usr/local/programs/postgresql/lib ## 刷新下共享动态库
$ cd /usr/local/programs/postgresql
$ bin/psql --version  ## 检查运行情况
## 开始对postgresql的配置
$ vi /etc/profile.d/postgresql.sh ## 增加环境变量,不推荐直接在/etc/profile中添加,系统更新升级时会需要merge
``` 
PATH=/usr/local/programs/postgresql:$PATH
export PATH
```
$ source /etc/profile ## 更新环境变量

## 增加用户和其他文件夹
$ adduser postgres
$ passwd postgres 
$ mkdir /usr/local/programs/postgresql/logs
$ mkdir /usr/local/programs/postgresql/data
$ chown postgres /usr/local/programs/postgresql/data
$ su - postgres

## 初始化数据库
$ ./bin/initdb -D ./data
$ ./bin/createdb test
$ ./bin/psql test
## 已有数据库,可导入data文件夹后尝试root访问,假如带密码,可能需要进一步研究下
$ ./bin/postgres -D ./data &gt;./logs/start-log-1.log 2&gt;&amp;1 &amp;
$ ./bin/psql --list  ##列出数据库
## ok,安装完成

## 自定义设置,权限控制等,可以跳过,等熟悉使用后再做
## 编辑数据库配置及权限文件:
$ vi /usr/local/programs/postgresql/data/postgresql.conf   ## 数据库配置文件
$ chown postgres postgresql.conf
$ chmod 644 postgresql.conf
$ vi /usr/local/programs/postgresql/data/pg_hba.conf   ## 权限文件
$ vi /usr/local/programs/postgresql/data/pg_ident.conf

## 设置开机自启动:
$ vi /etc/rc.d/rc.local    ## 添加如下内容
```
/usr/local/programs/postgresql/bin/postgresql start
```
登录后复制

5. 安装php

## 源码已经在第一步中下载,现在开始安装:
$ yum install libxml2 libxml2-devel libpng libpng-devel libjpeg libjpeg-devel freetype freetype-devel
$ ./configure \
--prefix=/usr/local/programs/php \
--with-apxs2=/usr/local/programs/apache2/bin/apxs \
--with-zlib \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-zlib-dir \
--enable-mbstring \
--with-pgsql=/usr/local/programs/postgresql \
--with-pdo-pgsql=/usr/local/programs/postgresql 
$ make
$ make test
&gt; Bug #42718 (unsafe_raw filter not applied when configured as default filter) [ext/filter/tests/bug42718.phpt]  XFAIL REASON: FILTER_UNSAFE_RAW not applied when configured as default filter, even with flags
&gt; Bug #67296 (filter_input doesn''t validate variables) [ext/filter/tests/bug49184.phpt]  XFAIL REASON: See Bug #49184
&gt; Bug #53640 (XBM images require width to be multiple of 8) [ext/gd/tests/bug53640.phpt]  XFAIL REASON: Padding is not implemented yet
&gt; zend multibyte (7) [ext/mbstring/tests/zend_multibyte-07.phpt]  XFAIL REASON: https://bugs.php.net/bug.php?id=66582
&gt; zend multibyte (9) [ext/mbstring/tests/zend_multibyte-09.phpt]  XFAIL REASON: https://bugs.php.net/bug.php?id=66582
&gt;Bug #70470 (Built-in server truncates headers spanning over TCP packets) [sapi/cli/tests/bug70470.phpt]  XFAIL REASON: bug is not fixed yet

## 查阅官方的bug,发现:
&gt; id=66582: status : Closed. Fixed in master (PHP7)
&gt; id=42718: status : Assigned
&gt; id=42718: reference to id=49184, unsolved for many years
## 那就不关心了,直接装吧
$ make install
&gt; You may want to add: /usr/local/programs/php/lib/php to your php.ini include_path

## 那就按它说的设置吧
$ cp php.ini-development /usr/local/programs/php/lib/php.ini
```
include_path = ".;/usr/local/programs/php/lib/php"

## 然后,编辑httpd的设置,确保其能正确解析php文件
```
...
LoadModule php5_module modules/libphp5.so
...
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .php5

...
<ifmodule dir_module>
    DirectoryIndex index.html index.php
</ifmodule>     
```

## 重启httpd,测试
$ cd /usr/local/programs/apache2
$ bin/httpd -h
$ bin/httpd -k stop
$ bin/httpd -f conf/httpd.conf
## 默认设置的www页面在./htdocs/下,那就先去里面建一个测试页面吧
$ vi htdocs/index.php
```
<?php phpinfo(); ?>
```
$ curl http://localhost/index.php |grep postgresql
#ok
登录后复制

后续应该做的事

* 1. 启动时,不需要要手动指定配置文件
* 2. php初始化www目录设置
* 3. php 用户、权限管理等

'').addClass(''pre-numbering'').hide(); $(this).addClass(''has-numbering'').parent().append($numbering); for (i = 1; i '').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了centos 7下源码编译安装php支持PostgreSQL,包括了postgresql,centos 7方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Postgres 中的组合 SQL 计数查询

Postgres 中的组合 SQL 计数查询

demos:db<>fiddle

SELECT 
    c.from_station,c.to_station,COUNT(*)
FROM stations s1
JOIN stations s2 ON s1.station <> s2.station                                     -- 1
JOIN connections c ON s1.station = c.from_station AND s2.station = c.to_station  -- 2
GROUP BY c.from_station,c.to_station                                            -- 3
  1. 在站表上创建自联接。 <> 加入条件确保不会加入同一个站。所有其他站将相互连接,从而创建所有组合
  2. 使用连接的 fromto 点的自连接中的两个站列在连接表上连接此结果
  3. 现在您可以按 fromtoCOUNT(*) 进行分组。

如果你想识别from站等于to站的情况,你可以改变

JOIN stations s2 ON s1.station <> s2.station

变成一个简单的:

CROSS JOIN stations s2

如果您想获得问题中所示的 JSON 对象:

SELECT 
    json_agg(connection)                      -- 2
FROM (
    SELECT 
        json_build_object(                    -- 1
            'fromStation',c.from_station,'toStation','count',COUNT(*)
        ) as connection
    FROM stations s1
    JOIN stations s2 ON s1.station <> s2.station
    JOIN connections c ON s1.station = c.from_station AND s2.station = c.to_station
    GROUP BY c.from_station,c.to_station
) s
  1. 根据您在上面创建的列创建您的 JSON 对象
  2. 将它们聚合成一个 JSON 数组。
,

先汇总行程,然后将 ID 解析为名称:

SELECT f.name AS from_station,t.name AS to_station,count
FROM  (
   SELECT from_station_id,to_station_id,count(*) AS count
   FROM   rides
   GROUP  BY 1,2
   ) r
JOIN   stations f ON f.id = r.from_station_id
JOIN   stations t ON t.id = r.to_station_id
ORDER  BY 1,2;  -- optional order

当然,这只会产生与实际骑行的组合。如果您需要包含没有任何游乐设施的组合,则需要将 OUTER 连接到 stations 表的笛卡尔积与自身。类似的东西:

-- include all combinations (even without rides)
SELECT from_station,to_station,COALESCE(count,0) AS count
FROM  (
   SELECT from_station_id,2
   ) r
RIGHT  JOIN (
   SELECT f.id AS from_id,f.name AS from_station,t.id AS to_id,t.name AS to_station
   FROM   stations f CROSS JOIN stations t
   ) s ON  s.from_id = r.from_station_id
      AND  s.to_id   = r.to_station_id
ORDER  BY 1,2;  -- optional order

同样,在加入车站之前汇总乘车次数会更便宜。

要将其包装为 JSON 数组或记录,只需:

SELECT json_agg(sub)
FROM  (
   -- query from above
   ) sub;

dbfiddle here

postgresql – Heroku – 无法通过Play Framework应用程序设置postgres数据库?

postgresql – Heroku – 无法通过Play Framework应用程序设置postgres数据库?

我试图通过播放框架应用程序在heroku上设置postgres数据库,但我一直收到关于我的DATABASE_URL的错误.

堆栈跟踪: –

-----> Heroku receiving push
-----> Play 2.0 - Java app detected
-----> Running: sbt clean compile stage
       Getting net.java.dev.jna jna 3.2.3 ...
       :: retrieving :: org.scala-sbt#boot-jna
        confs: [default]
        1 artifacts copied,0 already retrieved (838kB/25ms)
       Getting org.scala-tools.sbt sbt_2.9.1 0.11.2 ...
       :: retrieving :: org.scala-sbt#boot-app
        confs: [default]
        37 artifacts copied,0 already retrieved (7324kB/78ms)
       Getting Scala 2.9.1 (for sbt)...
       :: retrieving :: org.scala-sbt#boot-scala
        confs: [default]
        4 artifacts copied,0 already retrieved (19939kB/188ms)
       [info] Loading global plugins from /tmp/build_hdhsg4dgyxy/.sbt_home/.sbt/plugins
       [info] Updating {file:/tmp/build_hdhsg4dgyxy/.sbt_home/.sbt/plugins/}default-05c586...
       [info] Resolving org.scala-tools.sbt#sbt_2.9.1;0.11.2 ...
       [info] Resolving org.scala-tools.sbt#main_2.9.1;0.11.2 ...
       [info] Resolving org.scala-tools.sbt#actions_2.9.1;0.11.2 ...
       [info] Resolving org.scala-tools.sbt#classfile_2.9.1;0.11.2 ...
       [info] Resolving org.scala-tools.sbt#io_2.9.1;0.11.2 ...
       [info] Resolving org.scala-tools.sbt#control_2.9.1;0.11.2 ...
       [info] Resolving org.scala-lang#scala-library;2.9.1 ...
       [info] Resolving org.scala-tools.sbt#interface;0.11.2 ...
       [info] Resolving org.scala-tools.sbt#logging_2.9.1;0.11.2 ...
       [info] Resolving org.scala-tools.sbt#process_2.9.1;0.11.2 ...
       [info] Resolving org.scala-tools.sbt#classpath_2.9.1;0.11.2 ...
       [info] Resolving org.scala-tools.sbt#launcher-interface_2.9.1;0.11.2 ...
       [info] Resolving org.scala-lang#scala-compiler;2.9.1 ...
       [info] Resolving org.scala-tools.sbt#incremental-compiler_2.9.1;0.11.2 ...
       [info] Resolving org.scala-tools.sbt#collections_2.9.1;0.11.2 ...
       [info] Resolving org.scala-tools.sbt#api_2.9.1;0.11.2 ...
       [info] Resolving org.scala-tools.sbt#persist_2.9.1;0.11.2 ...
       [info] Resolving org.scala-tools.sbinary#sbinary_2.9.0;0.4.0 ...
       [info] Resolving org.scala-tools.sbt#compile_2.9.1;0.11.2 ...
       [info] Resolving org.scala-tools.sbt#ivy_2.9.1;0.11.2 ...
       [info] Resolving org.apache.ivy#ivy;2.2.0 ...
       [info] Resolving com.jcraft#jsch;0.1.31 ...
       [info] Resolving commons-httpclient#commons-httpclient;3.1 ...
       [info] Resolving commons-logging#commons-logging;1.0.4 ...
       [info] Resolving commons-codec#commons-codec;1.2 ...
       [info] Resolving org.scala-tools.sbt#completion_2.9.1;0.11.2 ...
       [info] Resolving jline#jline;0.9.94 ...
       [info] Resolving org.scala-tools.sbt#run_2.9.1;0.11.2 ...
       [info] Resolving org.scala-tools.sbt#task-system_2.9.1;0.11.2 ...
       [info] Resolving org.scala-tools.sbt#tasks_2.9.1;0.11.2 ...
       [info] Resolving org.scala-tools.sbt#tracking_2.9.1;0.11.2 ...
       [info] Resolving org.scala-tools.sbt#cache_2.9.1;0.11.2 ...
       [info] Resolving org.scala-tools.sbt#testing_2.9.1;0.11.2 ...
       [info] Resolving org.scala-tools.testing#test-interface;0.5 ...
       [info] Resolving org.scala-tools.sbt#compiler-interface;0.11.2 ...
       [info] Resolving org.scala-tools.sbt#precompiled-2_8_1;0.11.2 ...
       [info] Resolving org.scala-tools.sbt#precompiled-2_8_0;0.11.2 ...
       [info] Resolving org.scala-tools.sbt#precompiled-2_9_0;0.11.2 ...
       [info] Done updating.
       [info] Compiling 1 Scala source to /tmp/build_hdhsg4dgyxy/.sbt_home/.sbt/plugins/target/scala-2.9.1/sbt-0.11.2/classes...
       [info] Loading project deFinition from /tmp/build_hdhsg4dgyxy/project
       [info] Set current project to PostDemo (in build file:/tmp/build_hdhsg4dgyxy/)
       [success] Total time: 0 s,completed Jun 28,2012 2:20:47 AM
       [info] Updating {file:/tmp/build_hdhsg4dgyxy/}PostDemo...
[info] downloading http://repo.typesafe.com/typesafe/releases/postgresql/postgresql/9.1-901.jdbc4/postgresql-9.1-901.jdbc4.jar ...
       [info]   [SUCCESSFUL ] postgresql#postgresql;9.1-901.jdbc4!postgresql.jar (117ms)
       [info] Done updating.
       [info] Compiling 4 Scala sources and 4 Java sources to /tmp/build_hdhsg4dgyxy/target/scala-2.9.1/classes...
       [error] {file:/tmp/build_hdhsg4dgyxy/}PostDemo/compile:compile: com.typesafe.config.ConfigException$UnresolvedSubstitution: conf/application.conf: 37: Could not resolve substitution to a value: ${DATABASE_URL}
       [error] Total time: 10 s,2012 2:20:57 AM
 !     Failed to build app with sbt
 !     Heroku push rejected,Failed to compile Play 2.0 - java app
       error: Failed to push some refs to 'git@heroku.com.git'

我使用以下命令将DATABASE_URL设置为环境变量: –

echo "export DATABASE_URL=postgres://postgres:1234@localhost/Play">>.bash_profile
 . .bash_profile

我试图设置另一个URL,我发现使用命令heroku配置,我知道这是一个很长的postgres URL,但它没有工作,每次都出现相同的异常.

这是我在application.conf文件中添加的内容

%prod.db=${DATABASE_URL}

依赖

val appDependencies = Seq(
   "postgresql" % "postgresql" % "9.1-901.jdbc4"
)

所以现在我对我的DATABASE_URL感到困惑.为什么heroku无法用合适的值替换它. heroku在哪里寻找合适的URL?在我的application.conf文件中或在我的系统的bash配置文件中设置的环境变量中?

任何帮助将非常感激.

谢谢

编辑

日志

2012-06-28 20:38:18,500 - [INFO] - from play in main 
Listening for HTTP on port 9000...

2012-06-28 20:38:25,862 - [INFO] - from play in play-akka.actor.default-dispatcher-1 
database [default] connected at jdbc:postgresql://localhost/Play

2012-06-28 20:38:27,470 - [ERROR] - from application in New I/O server worker #1-1 


! @6aoffk4jk - Internal server error,for request [GET /login/?username=abc&&password=abc] ->

play.api.db.evolutions.InvalidDatabaseRevision: Database 'default' needs evolution! [An sql script need to be run on your database.]
    at play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart$1.apply(Evolutions.scala:424) ~[play_2.9.1.jar:2.0.1]
    at play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart$1.apply(Evolutions.scala:410) ~[play_2.9.1.jar:2.0.1]
    at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59) ~[scala-library.jar:0.11.2]
    at scala.collection.immutable.List.foreach(List.scala:45) ~[scala-library.jar:0.11.2]
    at play.api.db.evolutions.EvolutionsPlugin.onStart(Evolutions.scala:410) ~[play_2.9.1.jar:2.0.1]
    at play.api.Play$$anonfun$start$1.apply(Play.scala:60) ~[play_2.9.1.jar:2.0.1]
    at play.api.Play$$anonfun$start$1.apply(Play.scala:60) ~[play_2.9.1.jar:2.0.1]
    at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59) ~[scala-library.jar:0.11.2]
    at scala.collection.immutable.List.foreach(List.scala:45) ~[scala-library.jar:0.11.2]
    at play.api.Play$.start(Play.scala:60) ~[play_2.9.1.jar:2.0.1]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$3$$anonfun$1.apply(ApplicationProvider.scala:125) ~[play_2.9.1.jar:2.0.1]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$3$$anonfun$1.apply(ApplicationProvider.scala:112) ~[play_2.9.1.jar:2.0.1]
    at scala.Option.map(Option.scala:133) ~[scala-library.jar:0.11.2]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$3.apply(ApplicationProvider.scala:112) ~[play_2.9.1.jar:2.0.1]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$3.apply(ApplicationProvider.scala:110) ~[play_2.9.1.jar:2.0.1]
    at scala.Either$RightProjection.flatMap(Either.scala:277) ~[scala-library.jar:0.11.2]
    at play.core.ReloadableApplication$$anonfun$get$1.apply(ApplicationProvider.scala:110) ~[play_2.9.1.jar:2.0.1]
    at play.core.ReloadableApplication$$anonfun$get$1.apply(ApplicationProvider.scala:110) ~[play_2.9.1.jar:2.0.1]
    at akka.dispatch.Future$$anon$3.liftedTree1$1(Future.scala:195) ~[akka-actor.jar:2.0.1]
    at akka.dispatch.Future$$anon$3.run(Future.scala:194) ~[akka-actor.jar:2.0.1]
    at akka.dispatch.TaskInvocation.run(Abstractdispatcher.scala:83) ~[akka-actor.jar:2.0.1]
    at akka.jsr166y.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1381) ~[akka-actor.jar:2.0.1]
    at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259) ~[akka-actor.jar:2.0.1]
    at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:974) ~[akka-actor.jar:2.0.1]
    at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1478) ~[akka-actor.jar:2.0.1]
    at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104) ~[akka-actor.jar:2.0.1]

2012-06-28 20:38:30,150 - [WARN] - from play in New I/O server worker #1-1 
Applying evolution script for database 'default':

# !!! WARNING! This script contains DOWNS evolutions that are likely destructives

# --- Rev:2,Downs - eddafc8
delete from admins;
delete from employees;

# --- Rev:2,Ups - 822c4da
insert into admins (username,password) values ('abc','abc');
insert into admins (username,'abc');

insert into employees (id,name,email) values (1,'Super Man','superman@superhero.com');
insert into employees (id,email) values (2,'Bat man','batman@superhero.com');
insert into employees (id,email) values (3,'Spider Man','spidy@superhero.com');
insert into employees (id,email) values (4,'Iron Man','ironman@superhero.com');


2012-06-28 20:38:30,741 - [INFO] - from play in play-akka.actor.default-dispatcher-1 
database [default] connected at jdbc:postgresql://localhost/Play

2012-06-28 20:38:31,519 - [INFO] - from play in play-akka.actor.default-dispatcher-1 
Application started (Dev)
看来你正在混合一些Play 1和Play 2约定.看起来你正在使用Play 2.在Play 2中,设置它的最简单方法是不在application.conf中使用DATABASE_URL,而只是覆盖procfile中的数据库配置:
web: target/start -Dhttp.port=$PORT -DapplyEvolutions.default=true -Ddb.default.driver=org.postgresql.Driver -Ddb.default.url=$DATABASE_URL

有关更详细的演练,请参阅我的Play 2 Tutorial.

postgresql – Postgres中字符串的单词频率?

postgresql – Postgres中字符串的单词频率?

是否可以从Postgres中包含文本字符串的字段中识别每个字词和计数?
像这样的东西?
SELECT some_pk,regexp_split_to_table(some_column,'\s') as word
FROM some_table
@H_301_6@ 
 

获得不同的单词很容易:

SELECT disTINCT word
FROM ( 
  SELECT regexp_split_to_table(some_column,'\s') as word
  FROM some_table
) t
@H_301_6@ 
 

或得到每个单词的计数:

SELECT word,count(*)
FROM ( 
  SELECT regexp_split_to_table(some_column,'\s') as word
  FROM some_table
) t
GROUP BY word
@H_301_6@

我们今天的关于如何通过PostgreSQL中的组合来计算并发事件的频率/数量?的分享已经告一段落,感谢您的关注,如果您想了解更多关于centos 7下源码编译安装php支持PostgreSQL postgresql手册 postgresql官网下载 postgresql视频教、Postgres 中的组合 SQL 计数查询、postgresql – Heroku – 无法通过Play Framework应用程序设置postgres数据库?、postgresql – Postgres中字符串的单词频率?的相关信息,请在本站查询。

本文标签: