获得员工的母语和流利的语言

Get the MotherTongue and the Fluent language of an Employee(获得员工的母语和流利的语言)
本文介绍了获得员工的母语和流利的语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有以下查询,其结果是员工所说的语言及其相应级别:

I have the following query which gets as result the language spoken by an employee and his corresponding level :

SELECT E.EmployeeId
        ,ISNULL(L.ID ,0) AS LanguageId
        ,L.Label AS Language,
        ll.Label AS LanguageLevel
         FROM Employee e
LEFT JOIN AF_AdminFile aaf ON e.AdminFileId = aaf.AdminFileId
LEFT JOIN AF_Language al ON aaf.AdminFileId = al.AdminFileId
LEFT JOIN Language l ON al.LanguageId = l.ID
LEFT JOIN LanguageLevel ll ON al.LanguageLevelId = ll.LanguageLevelId
ORDER BY e.EmployeeId

结果如下:

对于 EmployeeId=6 的员工,他说英语/流利,西班牙语/好,法语/母语.
知道我的表 Language 中有 187 种不同的语言,我的表 LanguageLevel 中有 4 个语言级别(公平,流利,好,母语)

For the Employee with EmployeeId=6,he speaks English/Fluent, Spanish/Good,French/Mother Tongue.
Knowing that I have 187 different languages in my table Language and 4 language levels in my table LanguageLevel (Fair,Fluent,Good,Mother Tongue)

我只想获得母语和流利的语言,如下所示:

I want to get only the MotherTongue and the Fluent language like below :

EmployeeId MotherTongue        Fluent
6          French              English

推荐答案

当前查询的输出遵循非规范化键值存储的模式.在这种情况下,键是语言级别,值是语言.处理此问题的一种方法是按员工汇总,然后使用透视逻辑来获取您想要的语言.

The output from your current query follows the pattern of an unnormalized key value store. In this case, the keys are the language levels, and the values the languages. One way to handle this is to aggregate by employee and then use pivoting logic to obtains the languages you want.

SELECT
    e.EmployeeId,
    MAX(CASE WHEN ll.label = 'Mother Tongue' THEN l.label END) AS MotherTongue,
    MAX(CASE WHEN ll.label = 'Fluent' THEN l.label END) AS Fluent
FROM Employee e
LEFT JOIN AF_AdminFile aaf
    ON e.AdminFileId = aaf.AdminFileId
LEFT JOIN AF_Language al
    ON aaf.AdminFileId = al.AdminFileId
LEFT JOIN Language l
   ON al.LanguageId = l.ID
LEFT JOIN LanguageLevel ll
   ON al.LanguageLevelId = ll.LanguageLevelId
GROUP BY
    e.EmployeeId
ORDER BY
    e.EmployeeId;

这篇关于获得员工的母语和流利的语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Query with t(n) and multiple cross joins(使用 t(n) 和多个交叉连接进行查询)
Unpacking a binary string with TSQL(使用 TSQL 解包二进制字符串)
Max rows in SQL table where PK is INT 32 when seed starts at max negative value?(当种子以最大负值开始时,SQL 表中的最大行数其中 PK 为 INT 32?)
Inner Join and Group By in SQL with out an aggregate function.(SQL 中的内部连接和分组依据,没有聚合函数.)
Add a default constraint to an existing field with values(向具有值的现有字段添加默认约束)
SQL remove from running total(SQL 从运行总数中删除)