aggregate-functions

How to declare an array of rowtype in a PostgreSQL function?

不打扰是莪最后的温柔 提交于 2020-08-23 03:54:17
问题 I am trying to create a PostgreSQL function where I will loop over the rows of a query and store some of them in an array, before doing more stuff with it. How can I create an array of rowtype? CREATE OR REPLACE FUNCTION forExample() RETURNS integer AS $BODY$ DECLARE r "WEBHOST"%rowtype; b "WEBHOST"%rowtype[]; <- This does not work !!! BEGIN FOR r IN SELECT * FROM "WEBHOST" LOOP array_append(b, r); END LOOP; RETURN 33; END $BODY$ LANGUAGE 'plpgsql'; The above function will be more complex,

How to use MAX() on a subquery result?

放肆的年华 提交于 2020-08-21 08:58:54
问题 I am new to Oracle and the SQL world. I have a slight issue with a query that I cannot figure out for the life of me, I have spent a few hours trying different approaches and I cannot get the result I expect. So heres my query: SELECT * from(Select membership.mem_desc,membership.mem_max_rentals,membership_history.mem_type, count(membership_history.MEM_TYPE) as membership_count from membership_history JOIN membership ON membership.mem_type = membership_history.mem_type group by (membership

Cumulative adding with dynamic base in Postgres

為{幸葍}努か 提交于 2020-08-05 04:37:25
问题 I have the following scenario in Postgres (I'm using 9.4.1 ). I have a table of this format: create table test( id serial, val numeric not null, created timestamp not null default(current_timestamp), fk integer not null ); What I then have is a threshold numeric field in another table which should be used to label each row of test . For every value which is >= threshold I want to have that record marked as true but if it is true it should reset subsequent counts to 0 at that point, e.g. Data

AggregateCursor issue with MongoDB 3.6

给你一囗甜甜゛ 提交于 2020-08-02 17:54:10
问题 I've updated my MongoDB to the 3.6 version. I'm using a PHP MongoClient on CentOS 7 and PHP 5.5.38 . If I run the aggregateCursor method of the MongoDB library, through the first example reported in http://php.net/manual/en/mongocollection.aggregatecursor.php, I obtain the following error message as below: PHP Fatal error: Uncaught exception 'MongoCursorException' with message '95.110.150.99:27017: the command cursor did not return a correctly structured response' Do you have any idea about

AggregateCursor issue with MongoDB 3.6

谁说胖子不能爱 提交于 2020-08-02 17:48:54
问题 I've updated my MongoDB to the 3.6 version. I'm using a PHP MongoClient on CentOS 7 and PHP 5.5.38 . If I run the aggregateCursor method of the MongoDB library, through the first example reported in http://php.net/manual/en/mongocollection.aggregatecursor.php, I obtain the following error message as below: PHP Fatal error: Uncaught exception 'MongoCursorException' with message '95.110.150.99:27017: the command cursor did not return a correctly structured response' Do you have any idea about

AggregateCursor issue with MongoDB 3.6

橙三吉。 提交于 2020-08-02 17:48:11
问题 I've updated my MongoDB to the 3.6 version. I'm using a PHP MongoClient on CentOS 7 and PHP 5.5.38 . If I run the aggregateCursor method of the MongoDB library, through the first example reported in http://php.net/manual/en/mongocollection.aggregatecursor.php, I obtain the following error message as below: PHP Fatal error: Uncaught exception 'MongoCursorException' with message '95.110.150.99:27017: the command cursor did not return a correctly structured response' Do you have any idea about

How to create “likes count” Cloud Firestore aggregate function?

↘锁芯ラ 提交于 2020-06-17 13:21:47
问题 I am newb to firebase, I want to create an aggregate function for the likes count. I have three root collection: feeds, likes, and users. feeds have the following fields: description: <description of feed> likeCount:<Total count of like> title: <feed title> userId: <userId of feed> likes have the following fields: feedId: <id of the feed where a user gives like> likeBy: <id of the user who likes the feed> likeTo: <id of the user how created a feed> users have the following fields: username:

SQL group values for one column by another column

家住魔仙堡 提交于 2020-06-16 04:59:46
问题 Is there some kind of "aggregate" function in SQL that just turns values into a list? An example might be a table of the form: | game_id | player | score | |---------|--------|-------| | 1 | fred | 2 | | 1 | tom | 1 | | 2 | fred | 3 | | 2 | tom | 4 | What I would like returned is a table that looks like this: | player | scores | |--------|--------| | fred | 2, 3 | | tom | 1, 4 | The command might look something like: SELECT player, listify(score) FROM games GROUP BY player; 回答1: Thanks to Tim