SELECT shop,DATE_FORMAT(or_time,'%Y-%m') or_time,lopll,l_num FROM stock_out where shop in (SELECT shop FROM all_order_data.shop_channel where channel = '独唱团') and YEAR(or_time) >= 2021 GROUP BY shop,DATE_FORMAT(or_time,'%Y-%m'),lopll,l_num查询出每个shop,每个月,每个lopll的次数(count(l_num))
时间: 2024-02-05 22:13:37 浏览: 118
你可以尝试以下SQL语句:
```
SELECT shop,DATE_FORMAT(or_time,'%Y-%m') or_time,lopll,l_num,COUNT(l_num) num_of_l_num
FROM stock_out
WHERE shop IN (SELECT shop FROM all_order_data.shop_channel WHERE channel = '独唱团') AND YEAR(or_time) >= 2021
GROUP BY shop,DATE_FORMAT(or_time,'%Y-%m'),lopll,l_num;
```
这个查询语句会先从 `shop_channel` 表中选取所有 `channel` 为 "独唱团" 的店铺,并且选择 `or_time` 大于等于 2021 年的记录。然后,按照 `shop`、`or_time`、`lopll`、`l_num` 进行分组,并且计算每个组内 `l_num` 出现的次数。最后,将这些信息返回。
希望对你有帮助。
阅读全文