on 2011 Dec 11 4:58 AM
I have a row that has a quantity summed up by a primary key. Example:
quantity primary key ----------- ----------- 16 999383023
Is there a way to "un-sum" this quantity so that I'll have 16 rows of quantity = 1 and primary key remaining the same?
Purpose is to join this data with other tables that stratify this quantity further than the rolled up quantity of 16.
Using SQL Anywhere 11.
Appreciate the help.
Request clarification before answering.
For fans of the truly obscure, we bring you the LATERAL join operator...
CREATE TABLE t ( primary_key INTEGER NOT NULL PRIMARY KEY, quantity INTEGER NOT NULL ); INSERT t VALUES ( 999383023, 16 ); INSERT t VALUES ( 123456789, 5 ); COMMIT; SELECT t.primary_key, 1 AS quantity FROM t, LATERAL ( sa_rowgenerator ( 1, t.quantity ) ) AS unsum ORDER BY t.primary_key; primary_key,quantity 123456789,1 123456789,1 123456789,1 123456789,1 123456789,1 999383023,1 999383023,1 999383023,1 999383023,1 999383023,1 999383023,1 999383023,1 999383023,1 999383023,1 999383023,1 999383023,1 999383023,1 999383023,1 999383023,1 999383023,1 999383023,1
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
53 | |
6 | |
6 | |
5 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.