I need to export data from a SQL database (some groups use SQL Server, some Oracle, etc.) into a CSV where I need the id's from the joined table in a string.
For example, I have a table of Classes and a table of Students. From Classes, I need ID, Name, Section, Time, and from Students I need a string of the ID's of Students in the class. The results would return the columns: id,name,section,time,student_ids. The 'student_ids' column should be a delimited string, such as:
'32,43,53,12,41'
The row output would end up being something like:
"1405,Computer Science,101,12-1:30,'32,43,53,12,41'"
The number of Students per Class is not consistent, there could be one Student, or 20 Students. I thought about using a while loop using SQL Server to obtain this data, or a temp table that aggregates the keys, but I want to know if there is any way using standard SQL to accomplish this, so that the script can be portable.
Notes: I know the output format is not ideal, but the only other option is that we will have to pull a different record for each Class/Student combo, and then will have to aggregate the id's separately.