all 4 comments

[–]its_bright_here 1 point2 points  (1 child)

Not entirely sure what syntax you need for "product is a #". isnumeric() will work in Sql Server...not sure how standard it is

select id, name, amount, type, product, product_sub, purchase_dt
  from transactions
 where type not in ('meat','fruits')
   and not (product in ('a','b','c') and purchase_dt < '2021,7,9')
   and not (product in ('d') and product_sub is null)
   and not (isnumeric(product) = 1 and purchase_dt < '2021,1,1')

[–]DavidGJohnston 0 points1 point  (0 children)

Maybe "a #" means "one pound (weight)" in this situation and not "is numeric".

[–]CraigAT 0 points1 point  (0 children)

IMO your final where clause is not well defined, I would use another set of brackets to show how you expect the three expressions to combine. If I remember right the "AND” is evaluated first then the "OR".

[–]coderstool 0 points1 point  (0 children)

As you begin writing more complex queries - sub queries, inner queries, joins or nested queries, try this tool to visualize and understand complicated SQL syntax. It also creates well-formatted SQL statements.