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 7894889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:30:31+00:00 2026-06-03T07:30:31+00:00

I have a table with value look like this id time_stamp value 1 2013-01-01

  • 0

I have a table with value look like this

id         time_stamp                    value    
1          2013-01-01 00:00:15           10
2          2013-01-01 01:00:15            5
3          2013-01-02 00:00:15           15
4          2013-01-02 01:00:15           20
5          2013-02-01 00:00:15           18
6          2013-02-01 01:00:15           15
7          2013-02-02 00:00:15           5
8          2013-02-02 01:00:15           17
9          2014-01-01 00:00:15           8
10         2014-01-01 01:00:15            5
11         2014-01-02 00:00:15           15
12         2014-01-02 01:00:15           30
13         2014-02-01 00:00:15           18
14         2014-02-01 01:00:15           15
15         2014-02-02 00:00:15           5
16         2014-02-02 01:00:15           17

From this table I want to select the first record value and the last record value based on hour, day, month, year
For example I select value based on

Day:

id  time_stamp              start_value               end_value
1   2013-01-01              10                         5
2   2013-01-02              15                         20
3   2013-02-01              18                         15

and so on

Month:
id  time_stamp              start_value               end_value
1   2013 jan                10                         20
2   2013 feb                18                         17
3   2014 jan                8                          30
4   2014 feb                18                         17

Year:
id  time_stamp              start_value               end_value
1   2013                    10                         17
2   2014                    8                          17

How can I do this?

  • 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-03T07:30:33+00:00Added an answer on June 3, 2026 at 7:30 am

    Use mysql’s aggregation functions such as the following

    SELECT 
        t.id, 
        DATE_FORMAT(t.time_stamp, "%Y-%m-%d") AS time_stamp, 
        (SELECT `value` FROM table_name WHERE time_stamp BETWEEN DATE_FORMAT(t.time_stamp, "%Y-%m-%d 00:00:00") AND DATE_FORMAT(t.time_stamp, "%Y-%m-%d 23:59:59") ORDER BY id ASC LIMIT 1) AS start_value,
        (SELECT `value` FROM table_name WHERE time_stamp BETWEEN DATE_FORMAT(t.time_stamp, "%Y-%m-%d 00:00:00") AND DATE_FORMAT(t.time_stamp, "%Y-%m-%d 23:59:59") ORDER BY id DESC LIMIT 1) AS end_value
    FROM table_name t 
    GROUP BY DATE_FORMAT(t.time_stamp, "%Y-%m-%d")
    

    I’ve provided extra parameters on the query, to help you by keeping the query flexible 🙂

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

Sidebar

Related Questions

I have a table like this one: id group value 1 GROUP A 0.641028
I have a table that looks something like this: Name Year Value A 2000
For example I have a table MyTable like this: Id Value Rate 1 10
I have this JDBC SQL query: select * from table where TX_DATE = {d
I have a query that looks like the following: SELECT * FROM table WHERE
I have a user table that has many columns, it looks roughly like this:
if i have a table like this tbl_attributes --------------- id_attrib (auto incremented, primary key)
I have a mysql table that looks something like this: Row 1: 'visitor_input_id' =>
I have a table in MySQL. What would be the sql statement look like
We have a table value function that returns a list of people you may

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.