我有包含以下字段的表:
id | date_from | date_to | price -------------------------------------------- CK1 22-12-2012 29-12-2012 800 CK1 22-12-2012 29-12-2012 1200 CK2 22-12-2012 29-12-2012 1400 CK2 22-12-2012 29-12-2012 1800 CK2 22-12-2012 29-12-2012 2200
如何创建SQL,请选择按ID,DATE_FROM,DATE_TO对结果进行分组并从价格中选择最低的值。
所以结果是
CK1 22-12-2012 29-12-2012 800 CK2 22-12-2012 29-12-2012 1400
select id, date_from, date_to, min(price) from table group by id, date_from, date_to