How to view all data and replace with string when data no select in MySQL

I have problem to view all data when I put the create character represent for all group. I have field group in my table. The field has id 1, 2, 3, 4 and I also have put the case statement. When I put the id 1, then the result will be group1 and so on. What I want is when I put the character 'A'. Then the all data in group will display. How to do that? I have no idea.

This is my code:-

select case when a.group='1' then 'group1'
    when a.group='2' then 'group2'
    when a.group='3' then 'group3'
    when a.group='4' then 'group4'
    when a.group='A' then 'ALL GROUP'
    end as group
from kumpulan a
where (a.group = &GROUP or &GROUP = 'A')

if Group='A' then display 'Group 1','Group 2','Group 3','Group 4' in 4 rows

Answers


If problem is in 'group' column you should change a.group by &GROUP as:

select 
  case when &GROUP='1' then 'group1' 
  when &GROUP='2' then 'group2' 
  when &GROUP='3' then 'group3' 
  when &GROUP='A' then 'ALL GROUP' 
  end as group 
from 
 kumpulan a 
where (a.group = &GROUP or &GROUP = 'A')

I supose that this query is an abstrat of your real big query that may be something like:

select 
  case when &GROUP='1' then 'group1' 
  when &GROUP='2' then 'group2' 
  when &GROUP='3' then 'group3' 
  when &GROUP='A' then 'ALL GROUP' 
  end as `group` ,
  sum( some_column ) as total
from 
 kumpulan a 
where (a.group = &GROUP or &GROUP = 'A')
group by `group`

        select case 'A' when a.group='1' then 'group1' when a.group='2' then 'group2' when a.group='3' then 'group3' when a.group='A' then 'ALL GROUP' end as group from kumpulan a where (a.group = &GROUP or &GROUP = 'A');

Example for this:

       SELECT CASE 1 WHEN 1 THEN 'one' WHEN 2 THEN 'two' ELSE 'more' END;
    -> 'one'

Need Your Help

Multi-site deployment using git and a CI

php git github continuous-integration web-deployment

Currently, I'm using github to host my code repo and then pushing updates to my sites via copy and pasting files onto the server via FTP. However, the host I'm using allows ssh access there must be...

Intellij IDEA very slow while typing in editor (Scala only)

performance scala intellij-idea

Using IDEA 14.1.5 ultimate edition in Scala project there are a lot of performance problems. After typing a several symbols in the editor I have a lag for a few seconds. This happens only in Scala