查询未返回正确的结果

时间:2016-10-21 14:24:14

标签: sql

当我运行以下查询时,我会得到一个结果,但它看起来不正确。因此,其中某处肯定存在错误。

SELECT * 
FROM fe_users 
INNER JOIN user_managementsg_user_table AS umut ON 
         fe_users.uid = umut.fe_id 
     AND fe_users.city = 'Bern' 
      OR fe_users.city = 'Basel' 
      OR fe_users.city = 'Solothurn' 
      OR fe_users.city = 'Aargau' 
     AND umut.funktion = 'Assistenzarzt' 
      OR umut.fachgebiet_rheumatologie = 1 
      OR umut.taetigkeitsfeld = 'Praxis'

这就是我想要的:

fe_users.city是Bern OR Basel或Solothurn OR Aargau

umut.funktion是=' Assistenzarzt'或者umut.fachgebiet_rheumatologie = 1或者umut.taetigkeitsfeld =' Praxis'

当我在上面运行查询时,列city的某些值与我定义的4个城市不同。我的查询出了什么问题?

2 个答案:

答案 0 :(得分:1)

SELECT * FROM fe_users 
INNER JOIN user_managementsg_user_table AS umut 
ON fe_users.uid = umut.fe_id 
AND (fe_users.city in ('Bern','Basel','Solothurn','Aargau') 
AND (umut.funktion = 'Assistenzarzt' OR umut.fachgebiet_rheumatologie = 1 OR umut.taetigkeitsfeld = 'Praxis')

答案 1 :(得分:1)

试试这个。

SELECT  *
    FROM    fe_users
            INNER JOIN user_managementsg_user_table AS umut ON fe_users.uid = umut.fe_id
                                                            Where fe_users.city IN('Bern'
                                                               ,'Basel'
                                                               ,'Solothurn'
                                                               , 'Aargau')
                                                               AND (umut.funktion in('Assistenzarzt') OR umut.fachgebiet_rheumatologie = 1   OR umut.taetigkeitsfeld = 'Praxis'))