Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8504459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:02:21+00:00 2026-06-11T02:02:21+00:00

I have a table Date value1 value2 2012-09-07 1 1 2012-09-06 2 2 2012-09-05

  • 0

I have a table

Date        value1  value2
2012-09-07  1       1
2012-09-06  2       2
2012-09-05  3       3
2012-09-04  4       4
2012-09-03  5       5
2012-08-31  6       6
2012-08-30  7       7
2012-08-29  8       8
2012-08-28  9       9
2012-08-27  10      10
2012-08-24  11      11
2012-08-23  12      12
2012-08-22  13      13

values in the table is not ascending like in example. There are random numbers.

I need to get the date of the week start, value1 on the beginning of the week and value2 at the end of the week.

Date field is unique, and it’s stores day dates only so no duplicate dates are allowed.

I tried to use the query below:

SELECT MIN(`Date`) as Date, 
    (SELECT `value1` ORDER BY `Date` ASC LIMIT 1) as Start, 
    (SELECT `value2` ORDER BY `Date` DESC LIMIT 1) as End
FROM table
GROUP BY YEAR(`Date`), WEEK(`Date`,7)

The query returns grouped weeks and value1 correctly but value2 is also from the row of the week start i.e.

2012-08-27  10      10

but I need:

2012-08-27  10      6

What do I do wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:02:23+00:00Added an answer on June 11, 2026 at 2:02 am

    How about something like this

    SELECT `date`, value1 as Start, 
    (SELECT value2 FROM photos WHERE t.date >= adddate(`Date`, INTERVAL 1-DAYOFWEEK(`Date`) DAY) AND  t.date <= adddate(`Date`, INTERVAL 7-DAYOFWEEK(`Date`) DAY) ORDER BY date DESC LIMIT 1) as endDate
    from table t 
    GROUP BY YEAR(`Date`), WEEK(`Date`,7)
    

    There may be a more optimal way to do it.. but this works

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have table with a Date column called myDate , with values like
I have a table like ___________ | id | date | ----------- with values
I have a table with values like the following Name DatePurchased QuantityPurchased A 2/3/2012
I have a table of increasing dates (with gaps) and corresponding values date |
Imagine I have following table: NAME DATE OTHER_CONTANT 'A' '2012-06-05' 'baz' 'A' '2012-06-04' 'bar'
I have a table with day/time values that are split into date and an
I have 2 tables as below client_table date (timestamp) ip (varchar) value1 (int) value2
I have a table that have sigh in and sign out value **id Date
I have table with date/time column and person column. Each person has multiple records
I have table that contain date and time field. id|date|time ========= 1|01/01/2001|10:45 2|01/02/2002|11:45 3|01/03/2003|12:45

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.