select tbl_product.*, count(*) total
from tbl_product
where date(tbl_product.date) > date("2022-11-21") && date(tbl_product.date) > date("2022-11-29")
group by tbl_product.product_id
select tbl_product.product_id, count() total
from tbl_product
where date(tbl_product.date) >= str_to_date('2022-11-21','%Y-%m-%d')) and
date(tbl_product.date) <= str_to_date('2022-11-29','%Y-%m-%d'))
group by tbl_product.product_id
1条答案
按热度按时间eivgtgni1#
选择列而不是表https://dev.mysql.com/doc/refman/8.0/en/select.html,mysql字符串用单引号括起来When to use single quotes, double quotes, and backticks in MySQL,将字符串转换为日期https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_str-to-date,测试日期范围-两个测试都〉