[英]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. 该字段具有id
1、2、3、4,并且我也输入了case语句。 When I put the id
1, then the result will be group1
and so on. 当我输入id
1时,结果将为group1
,依此类推。 What I want is when I put the character 'A'
. 我想要的是当我输入字符'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 如果Group ='A',则在4行中显示'Group 1','Group 2','Group 3','Group 4'
If problem is in 'group' column you should change a.group by &GROUP as: 如果“组”列中存在问题,则应通过&GROUP将a.group更改为:
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'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.