0

我有一个存储以下数据的表:

recordDate  itemID  price
2012-03-30  2       15.1
2012-03-30  13      15.1
2012-04-06  2       15.2
2012-04-06  13      15.3
2012-04-15  2       16.2
2012-04-16  13      16.3
2012-04-26  2       14.9
2012-04-26  13      15.0
...

我想要一份从周五开始到下周四结束的每周报告。并且所选数据仅记录在给定日期。

例如:startDate = "2012-04-01", endDate = "2012-04-30"

我的预期结果是这样的:

weekStart   weekEnd     itemID   price
2012-04-06  2012-04-12  2        15.2
2012-04-06  2012-04-12  13       15.3
2012-04-13  2012-04-19  2        16.2
2012-04-13  2012-04-19  13       16.3
2012-04-20  2012-04-27  2        14.9
2012-04-20  2012-04-27  13       15.0
...

我怎样才能得到这个结果?我不熟悉 SQL,所以我不知道如何编写语句。

4

2 回答 2

0
SELECT 
  DAYNAME('2012-04-06') AS `start_week`,
  DAYNAME('2012-04-12') AS `End_week`,
  item_id,
  price 
FROM
  store 
WHERE record_date BETWEEN '2012-04-06' 
  AND '2012-04-12' ;

尝试这个 ?

于 2012-04-10T11:07:19.370 回答
0
SELECT * from store where DAYNAME(recordDate) in ('Friday','Saturday','Sunday','Monday','Tuesday') and 
start_date = '2012-01-01' and end_date = '2012-04-10'
于 2012-04-10T11:39:45.477 回答