Questions tagged [string-aggregation]

16 questions
21
votes
1 answer

Why is my ORDER BY in STRING_AGG not always working?

I have a table that consists of a record ID, a group ID (linking 1 or more records into a group) and a hash value for each record. CREATE TABLE HashTable( RecordID VARCHAR(255), GroupIdentifier VARCHAR(255), Hash VARCHAR (255), …
Rebecca
  • 321
  • 1
  • 2
  • 4
2
votes
2 answers

How to "flatten" multiple rows with same ID (Oracle 11g) by concatenating **multiple** fields per row?

I'm connected to an Oracle Database (11g Release 2 - 11.2.0.4). I'd like to "flatten"/"merge" all rows with the same ID, pretty much as is well delineated here:…
1
vote
1 answer

json_agg with dynamic 0-level key

I'm migrating a schema from NoSQL to postgres. Today's object "b" exists in NoSQL as an element of object a & looks in source like this... { "a": { "id": 1, "b":{ "c1": { "d1": 1, "d2": 2 }, "c2": { …
Peter Vandivier
  • 5,485
  • 1
  • 25
  • 49
1
vote
3 answers

Join Comma Separated Same Value

create table dbo.CourseMaster ( CourseId char(2), CourseName char(3) ); create table dbo.StudentMaster ( ROLLNO char(5), NAME varchar(10), ADDRESS varchar(20), Course varchar(100) ); insert into dbo.CourseMaster values ('01',…
patel akash
  • 11
  • 1
  • 4
0
votes
0 answers

How can I make a function similar to String_agg in Sql Server 2016?

I know that I will use stuff and for xml for this process, but in this way, the sentence like the one below becomes too long. Unfortunately I don't actually have a table like "controlTable". I actually write a long sentence to generate the…
omerix
  • 101
  • 1
  • 1
  • 7
0
votes
1 answer

How to merge and transform data in Postgres

A sql query yields data that looks like this: name quality magnitude john kindness 7 john greed 2 jane kindess 3 jane greed 7 john temper 9 jane temper 4 I am wondering if there is a way to transform it into data that looks…
ritratt
  • 105
  • 2
0
votes
1 answer

How can I group multiple records as a single .csv string line?

I have a relation where a User has multiple dogs (as many as 15) but each dog is contained in a single row in the table, and they all have a userId in common. For example, Table `dogs`: | User | Dog Name | Age | ABCD | Fido …
0
votes
1 answer

String aggregation using STUFF

Let's say I have table #DOC like…
0
votes
1 answer

general design pattern for smushing rows into one column

I have a table of people : id, person_name I have a table of tags: id, tag_name there is a junction table for the tags that connects people and tags: id, person_id, tag_id I have a query to get a group of people based on different search criteria so…
0
votes
1 answer

Postgresql, escape character in string_agg function

Question, can I add escape character \ just for fields param_name and value for this? string_agg(distinct '{name:"' || param_name || '",value:"' || value || '"}',',') as "params", Result is. {name:"připojení",value:"1/2""}, I need this (use \…
genderbee
  • 183
  • 1
  • 5
  • 16
0
votes
1 answer

Another - ERROR: column "da2.dependency_device_name" must appear in the GROUP BY clause or be used in an aggregate function

I am attempting to aggregate dependency_device_name into one string, "Dependency List". Here is the error: ERROR: column "da2.dependency_device_name" must appear in the GROUP BY clause or be used in an aggregate function. Here is the sql. I…
0
votes
1 answer

Recursive CTE throws temp tablespace is empty error

I need to aggregate the contents of multiple rows into a row as a delimited text. Here's the simplified table with sample data which represents what i want to do. CREATE TABLE SPD_OWNER.EMP ( EMPID NUMBER, NAME VARCHAR2(20), MGRID…
-1
votes
2 answers

How to get column values in where condition in sub query?

I am trying to get distinct list of values in where condition through sub query but it shows 0 rows in result set. Here is my query. SELECT a.topic_id, t.id as topicid, t.value as value, t.topic as topic, COUNT(c.topic_id) as count FROM post_topics…
prabhu
  • 23
  • 1
  • 7
-1
votes
1 answer

query with LISTAGG() string function does not return the desired output

I'm new to ORACLE and I'm trying to use a string aggregation function in my query to concatenate the value of rows with a comma , this is the structure of my tables: Student(STUDENT_ID,student_name,age) Course(course_no,description) …
Pantea
  • 1,510
  • 5
  • 31
  • 59
-2
votes
1 answer

Query that flattens many tables, but now want to concatinate one set of strings into a single string

I have an SP that flattens a bunch of tables. I recently refactored so that instead of a single description in one table I now have a one to many relationship with a descriptions table. I can inner join and get the descriptions on many rows, but…
Paul Gibson
  • 149
  • 6
1
2