Ask for sql sentence?

the Buy, attribute of the data table is the product product, department department, time time, so how to write the sql statement "products purchased by the sales department in 2014 but not purchased by other departments", I have been thinking about it for a long time, but I really can"t figure it out.

Mar.05,2021

SELECT * FROM Buy WHERE id not in (SELECT id where department! = 'sell' and? > time >?) Where? > time >? And department = 'sell';


select distinct product from buy where department = 'sales Department' and left (convert (varchar (10), time,120), 4) = '2014' and
not exists (select distinct product from where department! =' sales Department 'and left (convert (varchar (10), time,120), 4) =' 2014')
this is the writing of sql server. I'm not sure if mysql is the same syntax, if the above functions are used differently. Baidu can do it in one fell swoop


--departmentintdepartment=5
SELECT DISTINCT product FROM [Buy] 

WHERE department=5 AND time=2018 AND Title NOT IN
                                                (
                                                   SELECT DISTINCT product FROM [Buy] WHERE department<>5 AND time=2018
                                                )
--
Menu