Questions tagged [string-aggregation]

This tag is intended for SQL questions where multiple string (character) values should be aggregated into a single value using GROUP BY. The equivalent of sum() - just for strings.

The ISO/IEC SQL standard function for this is LISTAGG, but several DBMS:es have their own string aggregation functions:

386 questions
-1
votes
5 answers

Native Oracle Query to fetch One to Many Relationship Structure

Can any one please help me out for a query to fetch one to many relationship in oracle Table Structure is: Table: STUD_NAME Table:CLASS STUD_No STUD_Name Class_ID STUD_No …
SANJAY
  • 9
  • 4
  • 8
-1
votes
1 answer

SQL: Use STRING_AGG with condition

I have the following PostgreSQL query: (This is a Kata at codewars, you can find it at the following link: https://www.codewars.com/kata/64956edc8673b3491ce5ad2c/train/sql ) SELECT * FROM ( SELECT s.id AS student_id, MIN(s.name) AS name, …
Amir saleem
  • 1,404
  • 1
  • 8
  • 11
-1
votes
3 answers

SQL concatenate row by row by date order with in group

I am looking for a way to concatenate the rows into a comma separated string. Example: I am looking for result as below where Result Seq column should concatenate the result column row by row values in order of Inspectiondate within group of…
Mohan.V
  • 141
  • 1
  • 1
  • 10
-1
votes
1 answer

What's the best way to create a string of childIDs for each parentID in SQL, while excluding the current childID from the aggregate

Data DROP TABLE IF EXISTS cats; CREATE TABLE cats ( litterID int NOT NULL, catID int NOT null, --row uniquifier catFirst varchar(30), catLast varchar(30), catSize int ); INSERT INTO cats…
Mike G
  • 712
  • 5
  • 9
-1
votes
1 answer

How to find the column of a specific value in a table (SQL Server)

I have a table with more than 10,000 records. When executing the query, I get an error message Msg 245, Level 16, State 1, Line 10 Conversion failed when converting the varchar value 'balance' to data type int The problem is I don't know which…
-1
votes
2 answers

Concat data from different rows into one in BigQuery

i want to concat my data from a particular column which is present in different rows. The Data is something like this: id | Name | 1 | Jack, John | 2 | John | 3 | John, Julie | 4 | Jack | 5 | Jack, Julie | I want the output as Jack, John, Julie.…
-1
votes
1 answer

Join of data from one column into one string

in postgreSQL database I have table with Name(string) column. ID| Name 1 | a 2 | b 3 | c 4 | d With one query I would like to retrieve all names from the table into one string in the format: 'a', 'b', 'c', 'd'
panmigal
  • 101
  • 2
  • 7
-1
votes
1 answer

Get the same result result of my query as a scalar function

I created a user defined string_agg as a query and it's working fine I want to convert it to a scalar function but it is not returning the same result. My query SELECT STUFF( (SELECT '-' + CAST(Namess AS VARCHAR(20)) AS [text()] FROM…
-1
votes
2 answers

SQL groupings for desired expected report

The requested result is: styleNumber colorCode asset.url 1021A166 600 https://IMAGE , https://IMAGE 1, https://IMAGE 2,https://IMAGE 3,https://IMAGE 4 1021A163 1 https://IMAGE , https://IMAGE 1, https://IMAGE 2,https://IMAGE 3, And I do…
-1
votes
2 answers

Convert distinct records under one column into one singular row?

I have a table where all the records are identical, besides the values in one column. Something like this: City Warehouse OrderID CustomerID San Diego SD1 1234 5678 San Diego SD2 1234 5678 San Diego SD3 1234 5678 What SQL…
nz426
  • 91
  • 1
  • 10
-1
votes
1 answer

Query to get distinct results

I have a query to get data from multiple tables. But somehow, I got duplicate entries from database due to one column. The query is: SELECT BH.BusinessName, AppointmentStartTime, AppointmentEndTime, AppointmentStatus, AppointmentFor,…
-1
votes
1 answer

Oracle Sql select all values in a row without using aggregate functions and procedures

I have this code: select eto.id,( epe.surname || ' ' || epe.name || ' ' || epe.patronymic) fio from employee_trip_orders eto left join employee_card_order_links ecol on eto.id…
Vytsalo
  • 670
  • 3
  • 9
  • 19
-1
votes
1 answer

SQL query with listagg (distinct ) and case statement

I need to use listagg(distinct somestring) except I need to select the records conditionally, hence I combine a case statement within the listagg. here is a sample of the code which works : listagg(case when level_1='Brakes' and service_r_L>0.8…
user32457
  • 21
  • 1
-1
votes
1 answer

Group SQL rows with same column value into one row?

Is it possible to group SQL rows with the same column value into one row?
Ryan
  • 1
-1
votes
1 answer

SQL Express concat while condition is met

My table looks something like this (with 7500 rows): UserName Company Eduard Google Alex Google Mark Google Silvia Microsoft Any I need it to look like this: UserName Company Eduard, Alex, Mark …