这个sql 怎么写 mysql的数据库

如下:取每个月内的最小price项的id, name不同的要区分 表名 goods
id name     date         price        
1   aaa     2016-11-4     100      
2   aaa     2017-1-4       100      
3   aaa     2017-1-6       90        
4   aaa     2017-2-4       120      
5   aaa     2017-3-4       110      
6   aaa     2017-3-7       100
7   aaa     2017-1-9       90 
8   bbb     2016-11-4     100      
9   bbb     2017-1-4       100      
10 bbb     2017-1-6       90        
11 bbb     2017-2-4       120      
12 bbb     2017-3-4       110      
13 bbb     2017-3-7       100
14 bbb     2017-1-9       90 

SELECT min(price),SUBSTR(date_format(date, '%Y%m-%d'),1,INSTR(date_format(date, '%Y%m-%d'),'-')) FROM BASE_USER GROUP BY SUBSTR(date_format(date, '%Y%m-%d'),1,INSTR(date_format(date, '%Y%m-%d'),'-')),name;

select id,date,name,min(price) as price from goods group by date_format(date,'%y-%m'),name;

select *,min(price) as price from goods group by date_format(date,'%y-%m'),name;

建议交给代码层面去区分这层关系

select id,date_format(date,'%Y-%m') month,price from goods group by month,name order by price