Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 在串联列中与ms sql中的表不同_Mysql_Sql Server_Concatenation_Distinct_Distinct Values - Fatal编程技术网

Mysql 在串联列中与ms sql中的表不同

Mysql 在串联列中与ms sql中的表不同,mysql,sql-server,concatenation,distinct,distinct-values,Mysql,Sql Server,Concatenation,Distinct,Distinct Values,我在数据库中运行此查询,结果不明显。在select子句中使用连接时,是否有任何解决方案可以获得不同的结果 select case when c.SubtypeId_FK is null then c.TypeDescription else c.TypeDescription + ' In ' + cs.Subtype end as Experties from CaseTLS c, CaseLawyer cl ,

我在数据库中运行此查询,结果不明显。在select子句中使用连接时,是否有任何解决方案可以获得不同的结果

select
    case 
        when c.SubtypeId_FK is null then c.TypeDescription 
        else c.TypeDescription + ' In ' + cs.Subtype 
    end as Experties
from 
    CaseTLS c, 
    CaseLawyer cl , 
    Lawyer l , 
    CaseSubtype cs
where
    c.CaseId = cl.CaseID  
    and cl.ComputerCode = l.ComputerCode 
    and l.ComputerCode = @p1 
    and (
        c.SubtypeId_FK = cs.SubtypeId or c.SubtypeId_FK is null
    )
试试这个:

select
     DISTINCT case 
        when c.SubtypeId_FK is null then c.TypeDescription 
        else c.TypeDescription + ' In ' + cs.Subtype 
    end as Experties
from 
    CaseTLS c, 
    CaseLawyer cl , 
    Lawyer l , 
    CaseSubtype cs
where
    c.CaseId = cl.CaseID  
    and cl.ComputerCode = l.ComputerCode 
    and l.ComputerCode = @p1 
    and (
        c.SubtypeId_FK = cs.SubtypeId or c.SubtypeId_FK is null
    )

只需在select子句中使用Distinct。

使用
select Distinct case..
。如果可能,添加样本数据和预期输出,这将帮助您获得正确答案。
select
    case 
        when c.SubtypeId_FK is null then c.TypeDescription 
        else c.TypeDescription + ' In ' + cs.Subtype 
    end as Experties
from 
    CaseTLS c, 
    CaseLawyer cl , 
    Lawyer l , 
    CaseSubtype cs
where
    c.CaseId = cl.CaseID  
    and cl.ComputerCode = l.ComputerCode 
    and l.ComputerCode = @p1 
    and (
        c.SubtypeId_FK = cs.SubtypeId or c.SubtypeId_FK is null
    )