我正在试着做一个查询,但它不正确。
我想做的是应用join以防
我的问题是
SELECT LEFT(Student_First_Name,LEN(Student_First_Name)-LEN(Name_Lookup_Table.Dirty_Name)),Name_Lookup_Table.Dirty_Name, Name_Lookup_Table.Standard_Name
case
when Transformed_All_Student.Student_First_Name like '% '+Name_Lookup_Table.Dirty_Name
then
from Transformed_All_Student left join Name_Lookup_Table
on Transformed_All_Student.Student_First_Name like '% '+Name_Lookup_Table.Dirty_Name
when Transformed_All_Student.Student_First_Name like '% '+Name_Lookup_Table.Dirty_Name+'%'
then from Transformed_All_Student left join Name_Lookup_Table on Transformed_All_Student.Student_First_Name like '% '+Name_Lookup_Table.Dirty_Name+'%'
when Transformed_All_Student.Student_First_Name like Name_Lookup_Table.Dirty_Name+'% '
then from Transformed_All_Student left join Name_Lookup_Table on Transformed_All_Student.Student_First_Name like Name_Lookup_Table.Dirty_Name+'% '有人能帮上忙吗?
发布于 2012-12-28 03:58:42
我不认为你能把它放在什么时候。一种可能的解决方案是使用UNION。您可能可以优化以下内容:
SELECT LEFT(Student_First_Name
, LEN(Student_First_Name)-LEN(nlt.Dirty_Name))
, nlt.Dirty_Name
, nlt.Standard_Name
FROM Transformed_All_Student tas
LEFT JOIN Name_Lookup_Table nlt
ON tas.Student_First_Name like '% '+nlt.Dirty_Name
WHERE tas.Student_First_Name like '% '+nlt.Dirty_Name
UNION
SELECT LEFT(Student_First_Name
, LEN(Student_First_Name)-LEN(nlt.Dirty_Name))
, nlt.Dirty_Name
, nlt.Standard_Name
FROM Transformed_All_Student tas
LEFT JOIN Name_Lookup_Table nlt
ON tas.Student_First_Name like '% '+nlt.Dirty_Name+'%'
WHERE tas.Student_First_Name like '% '+nlt.Dirty_Name+'%'
UNION
SELECT LEFT(Student_First_Name
, LEN(Student_First_Name)-LEN(nlt.Dirty_Name))
, nlt.Dirty_Name
, nlt.Standard_Name
FROM Transformed_All_Student tas
LEFT JOIN Name_Lookup_Table nlt
ON tas.Student_First_Name like nlt.Dirty_Name+'% '
WHERE tas.Student_First_Name like nlt.Dirty_Name+'% '发布于 2012-12-28 03:55:04
既然您正在尝试这样做,我假设性能不是主要考虑因素。另外,我假设这是为MS SQL,因为没有另外指定。一般形式如下:
SELECT 1
FROM foo f
JOIN bar b
ON CASE WHEN f.col1 = 'X' then 'Y' ELSE END = b.col1获得相同结果的另一种可能方法是使用子查询:
SELECT 1
FROM (
SELECT *, CASE WHEN f.col1 = 'X' then 'Y' ELSE END JoinCol
FROM foo
) f
JOIN bar b
ON f.JoinCol = b.col1可能还有其他几种方法。如果您能给我们一个涉及的表和您想要在输出中的列的快速定义,那将是最好的。
希望这能有所帮助。
https://stackoverflow.com/questions/14060383
复制相似问题