当前位置: 动力学知识库 > 问答 > 编程问答 >

mysql - Can anyone explain to me what this query does?

问题描述:

I need the riposte in layman's language.

SELECT

t1.*

, IF(isBranch='true','',IF(pointsweightage IS NULL,'Not Set',pointsweightage)) AS w

, t2.id AS wid

FROM

`skills_hierarchy` t1 LEFT JOIN

weightage t2 ON t1.pointsweightage=t2.weightage

WHERE

isBranch='false'

AND t1.deptid=$deptid

AND t2.deptid=$deptid

I want the Query to be changed such that it gets me the data of the department which it does login.

网友答案:

Well, I'm going to re-format this a bit to help you out, then I'll explain below.

SELECT 
    t1.*,
    IF(isBranch='true',
        '',
        IF(pointsweightage IS NULL,
            'Not Set',
            pointsweightage)) AS w,
    t2.id AS wid 
FROM `skills_hierarchy` t1 
    LEFT JOIN weightage t2 
        ON t1.pointsweightage=t2.weightage 
WHERE isBranch='false' 
    AND t1.deptid=$deptid 
    AND t2.deptid=$deptid

The "Select" portion gets you all values from the "skills_hierarchy" table, then a value for a column called "w". This value will be one of three things.

  1. An empty value if isBranch is equal to true
  2. A Value 'Not Set' if pointsweightage is null
  3. The value of pointsweightage if 1 and 2 do not apply

The query is already filtering out results based on a parameter value of $deptid

分享给朋友:
您可能感兴趣的文章:
随机阅读: