this is slightly above my ability. i guess there must be an elegant solution to this but i don't know what it might be and i suspect that even if i did, i wouldn't know how to implement it, so any help very gratefully received.
i have, in my table, an integer field which stores a number corresponding to which category (or categories) a record falls into. let's say the categories are "A", "B", "C" or "none".
0 - none
1 - A
2 - B
4 - C
so, e.g. if a document falls into categories A and C, the int field stores 5, the sum of 1 and 4.
then, to find out which categories a record falls into, i select on a bitwise result.
e.g.
select
record_id,
case (category & 1) when 0 then '' else 1 end as A,
case (category & 2) when 0 then '' else 1 end as B,
case (category & 1) when 0 then '' else 1 end as C
where category > 0
order by record_id
...which gives me a recordset with as many records as are categorised, with a boolean value for each category
(when i was doing this, i thought it was very elegant and clever. i guess this is nothing new to lots of you, though!)
now, i need to list all the records, grouping them by category. if a document has more than one category selected, it should appear under each category.
i guess i need a self-join and a subquery for this, but as i say, i can't quite work out the concept.
here is an example of the recordset produced by the above code and then what i want to achieve.
what i have...
[tt]
fun hard sweaty
golf 1 1
pool 1
soccer 1 1
runnng 1
[/tt]
what i want...
[tt]
golf fun
pool fun
soccer fun
golf hard
soccer sweaty
running sweaty
[/tt]
many thanks for any ideas!
i have, in my table, an integer field which stores a number corresponding to which category (or categories) a record falls into. let's say the categories are "A", "B", "C" or "none".
0 - none
1 - A
2 - B
4 - C
so, e.g. if a document falls into categories A and C, the int field stores 5, the sum of 1 and 4.
then, to find out which categories a record falls into, i select on a bitwise result.
e.g.
select
record_id,
case (category & 1) when 0 then '' else 1 end as A,
case (category & 2) when 0 then '' else 1 end as B,
case (category & 1) when 0 then '' else 1 end as C
where category > 0
order by record_id
...which gives me a recordset with as many records as are categorised, with a boolean value for each category
(when i was doing this, i thought it was very elegant and clever. i guess this is nothing new to lots of you, though!)
now, i need to list all the records, grouping them by category. if a document has more than one category selected, it should appear under each category.
i guess i need a self-join and a subquery for this, but as i say, i can't quite work out the concept.
here is an example of the recordset produced by the above code and then what i want to achieve.
what i have...
[tt]
fun hard sweaty
golf 1 1
pool 1
soccer 1 1
runnng 1
[/tt]
what i want...
[tt]
golf fun
pool fun
soccer fun
golf hard
soccer sweaty
running sweaty
[/tt]
many thanks for any ideas!