android - Merge different rows to one and count how many rows were merged -
let's have following rows in table:
externalid count descriptor 1 1 val-1 1 1 val-2 2 1 val-3 2 1 val-4 2 1 val-5 2 1 val-6 3 1 val-7
i need accomplish this:
externalid count descriptor 1 2 val-1, val-2 2 3 val-3, val-4, val-5 3 1 val-7
would possible?
it possible perhaps not done thing/best utilisation of available features of relational databases.
this appears case utilising advtanges of relationships.
how considering table external id's , table descriptors , link table (assocciative table or many other names uses tables tie relationships).
e.g.
create table externals (_id primary integer key, extid integer) create table descriptors (_id primary integer key, descriptor text) create table link_externals_to_descriptors (external_ref integer not null, descriptor_ref integer not null)
so above have (note i've used id's 10-12 , 100-106 distinguish them illustration purposes):-
externals table
_id extid 10 1 11 2 12 3 99 9
descriptors table
_id descriptor 100 val-1 101 val-2 102 val-3 103 val-4 104 val-5 105 val-6 106 val-7
link table (link_externals_to_descriptors)
external_ref descriptor_ref 1 100 1 101 2 102 2 103 2 104 3 106 99 100 99 102 99 104 99 105 99 107
this may seem , may overly complex copes one-many, many-one , many-many relationships between externalid's , descriptors.
i.e. 99 equivalent to
9 val-1, val-3, val-5, val-6, val-7
(all except val-6 being used others)
there no need merge or un-merge, split csv individual descriptors. want. e.g.
select * link_externals_to_descriptors external_ref = 99;
being used drive query return cursor who's count (number of rows) number of descriptors external id.
as such, following used count , descriptors (outputting info log) :-
cursor csr = db.query("link_externals_to_descriptors", null, "external_ref=?", new string[]{"99"}, null,null,null); int my_count_of_descriptors = csr.getcount() log.d("myinfo","the number of descriptors extid 99 is" + integer.tostring(my_count_of_descriptors) + " are:-"); while(csr.movetonext) { log.d("myinfo","\t" + csr.getstring(csr.getcolumnindex("descriptor_ref"))); } csr.close();
Comments
Post a Comment