gpt4 book ai didi

mysql - 基于列中标志的 SQL View

转载 作者:行者123 更新时间:2023-11-29 11:36:30 25 4
gpt4 key购买 nike

我对 SQL 中非常忙碌的情况感到震惊。我有一个包含列 (name,is_right) 的表,我想获得如下 View :

Wrong Name|| Right Name 
Jass || Jasu

对于表

Name  || is_right
Jass || 0
Jasu || 1

我正在尝试寻找解决方案,但没有任何效果。请帮助我或指导我完成任何示例,以便我能够掌握它。

最佳答案

我假设您有用户的memberID。请假设@table 是您当前包含用户信息的表。我假设每个memberID只有一个值0和一个值1

declare @table table
(
memberID nvarchar(10),
name nvarchar(10),
is_right integer
)

insert into @table values ('A','Jass',0);
insert into @table values ('A','Jasu',1);
insert into @table values ('B','Pata',0);
insert into @table values ('B','Peter',1);

select distinct
(select B.name from @table B where b.is_right = 0 and B.memberID = A.memberID) as 'wrong name',
(select C.name from @table C where c.is_right = 1 and C.memberID = A.memberID) as 'right name'
from @table A
<小时/>

这就是它返回的内容

名字错误|正确的名字

贾斯 |贾苏

帕塔 |彼得

关于mysql - 基于列中标志的 SQL View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36493692/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com