Quote:
|
Originally Posted by fatalerror
... i will have to save this information in an already existing table and i cannot use a temp table to save these values ...
|
Given the first statement I quoted here, I don't understand at all why you initially said that no "variables, temp tables, global temp tables, or common table expressions (with clause)" are an option. Usually, such restrictions are imposed only in class exercises. Practical problems often allow you to search for all possible solutions and then picking the best approach - instead of reducing the solution space right away as you have done. I guess you will understand that all who responded to your question have this impression.
Could you explain to us why recursive queries (common table expressions) are not allowed, for instance? You could implement the CTE inside a table function and then use this table function in an INSERT statement - no materialized temp tables will be required (but DB2 uses a barrier to first build an intermediate result in memory, which is essentially a temp table) and the recursive CTE can be used in a straight-forward manner to do the concatenation. Likewise, XMLAGG does the aggregation of a bunch of XML values. The links provided above show how to use that function for your purposes. You can even throw this into a subselect and do whatever you want. You can process multiple nested groups on millions of rows if you like. Therefore, I think it is fair to raise the question what the problems with XMLAGG are. What have you tried? How were it failing/not producing the correct results?
Quote:
|
... and also aggregate functions imply to columns in the table
|
I didn't understand this part. Could you please explain what you mean by it? If you mean by "columns in the table" a column in a base table, you are mistaken. You can do aggregation on anything in SQL because - at the end of the day - everything is a table in SQL. Even a simple statement like this produces a table:
This is a table with one row and one column, so you could aggregate on it (or do whatever other features SQL provides, for example:
Code:
SELECT MIN(v)
FROM TABLE ( VALUES (123) ) AS t(v)
The only important part is that you properly define your groups on which an aggregation is to be applied.
p.s: I don't intend to bash MySQL now, but the way how some DBMS adhere to the SQL standard and implement relational concepts is sometimes not the best. Therefore, drawing conclusions for one DBMS based on experiences gathered on MySQL is often not a good idea.