访问SQL NOT LIKE查询

时间:2016-04-26 01:36:24

标签: sql ms-access

我试图返回salesperson_id和salesperson_lnames的列表,其中salesperson_id在FL或HI中没有客户。

我当前的查询是

requesting approaval from executives
requesting approval from Finance
requesting approval from Marketing
and now we play the waiting game

它返回一个列表,不包括salesperson_id和salesperson_lname,如果他们的客户在BOTH HI和FL中,而在HI或Fl中只有一个客户。

Relevant TableCurrent Output

1 个答案:

答案 0 :(得分:0)

如果我理解正确,您只想归还那些在HI或FL(或两者)中没有客户的销售人员。如果是这样,您可以使用having检查某个群组是否有HI或FL中的任何客户,如果他们这样做,则将其排除:

SELECT s.salesperson_id, s.salesperson_lname
FROM salesperson_t AS s 
INNER JOIN customer_t AS c on s.salesperson_id=c.salesperson_id
GROUP BY s.salesperson_id, s.salesperson_lname
HAVING COUNT(CASE WHEN c.state IN ('HI', 'FL') THEN 1 END) = 0