Reputation: 1
I am an amateur in learning, and I need some help.
I have one column with the following values that need to be grouped.
I have three groups of store numbers:
What I am trying to do is tell SQL to group them. So far all I have is: IF [Store ID] = "006" THEN "HCFP" END
How do I group more than one? and What is the correct way to do what I am trying to do?
Upvotes: 0
Views: 262
Reputation: 1269933
You can use a case
. In standard SQL, you can add a new column:
select t.*,
(case when storeid in (001, 002, 003, 004, 005, 006, 012, 014, 007)
then 'HCFP'
when storeid in (111, 112, 113, 114, 115, 116, 121, 122, 123, 317)
then 'SFP'
when storeid in (261, 262, 263, 264, 271, 273, 274, 275, 276, 277)
then 'HFP'
end) as region
I'm not sure what you want to do with the value, but this puts it on each output row.
Upvotes: 1
Reputation: 11896
In Tableau, you can select your field in the left sidebar, the right click and select 'create group'. You can then select the values that you want to treat the same, press the group button and name your grouped values as desired. Then use the new group field in your visualizations.
When generating SQL, this will have the same effect as a hand crafted case statement.
Upvotes: 0