I don’t know how many SQL gurus there are here so if anyone doesn’t know the answer but knows a site where I can post SQL questions, that would be appreciated too.
Anyway, the question:
I have a table with a few hundred thousand rows, each of which has an identifier of C1, C2 etc up to C21. The identifier is known as the segment.
To illustrate, if I execute
SELECT segment, count (*)
FROM my_table
GROUP BY segment
I get:
C1 12000
C10 10542
C11 10389
C12 10737
C13 12000
C14 12000
C15 12000
C16 12000
C17 48253
C18 24195
C19 39708
C2 12000
C20 24039
C21 24352
C3 12000
C4 12000
C5 13121
C6 16870
C7 41653
C8 16852
C9 16819
What I need to do is set 5% of each of the segments as a control. ie I want to set the “segment” column to be set to ‘CTRL’ for 5% of each segment.
Does anyone know a way to do this with a single command? It can be as complex as necessary, but must be a single statement.
Thanks in advance for any help.