Mysql
 sql >> Database >  >> RDS >> Mysql

Istruzione MySQL Inner Join if

Select user.userID
    , username
    , user.email
    , registeredBy, registeredDate
    , Case 
        When User.Level = 2 Then Concat(Level2Staff.firstName, ' ' , Level2Staff.lastName) 
        When User.Level = 1 Then Concat(customer.firstName, ' ' , customer.lastName) 
        End
        AS staffName 
FROM user
    Inner Join level
        On user.levelID = level.levelID 
    Inner Join staff
        On user.registeredBy = staff.UserID
    Left Join customer
        On customer.userID = user.UserID
            And user.level = 1
    Left Join staff As Level2Staff
        On user.userID = Level2Staff.UserID