MySQL. Products not sold in a period

China☆狼群 提交于 2021-01-28 18:24:58

问题


I am learning MySQL and I have a question. I have this following assignment and it's pretty new to me, but logically it's easy.

I have the following table:

 id          article_id   quantity     date_sold   price
  1                1            2      2014-05-05    200
  2                2            4      2014-05-12    800
  3                3            5      2014-05-02     35
  4                4            10     2014-05-18     60
  5                5            20     2014-05-23     20
  6                6            2      2014-05-20     26
  7                7            1      2014-05-14     10
  8                8            2      2014-05-12     30
  9                9            6      2014-05-11     12
  10               10           2      2014-05-08      6

And the question sounds like this "Determine the article not sold in a given period. The result would pretty much sound like this: Between 2014-05-10 and 2014-05-20, article 1, 3, 5, 10 have not been sold.


回答1:


Try this

  SELECT * from table1
  WHERE id NOT IN ( select id FROM table1 WHERE
             `date_sold` BETWEEN '2014-05-10' and '2014-05-20')

this will give you result of articles which have not been sold between the given dates.

DEMO HERE



来源:https://stackoverflow.com/questions/23857059/mysql-products-not-sold-in-a-period

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!