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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:48:19+00:00 2026-05-27T10:48:19+00:00

Hi i have a table with the following fields ‘Site Code’ ‘Date’ ‘Hour’ ‘Quantity’

  • 0

Hi i have a table with the following fields ‘Site Code’ ‘Date’ ‘Hour’ ‘Quantity’ and i want in a query to take all the inputed data of the last week. But there can be more than one inputs for one date so i will have to group according to Date first and then order those groups in DESC and take the last 7. The query i am using however does not work as it should because it orders the groups but in days with multiple inputs i am getting only 1 of them.
the query is:

SELECT `Quantity` , `Hour` , `Date`
FROM (
      SELECT *
      FROM `13_trans_coffee`
      WHERE `Site Code` =103713
      GROUP BY `Date`
      ORDER BY `Date` DESC
     )days
LIMIT 0 , 7

sample data

site code  date            hour    quantity
103713     5/12/2011 0:00  21      10
103713     5/12/2011 0:00  20      11
103713     4/12/2011 0:00  14      10
103713     6/12/2011 0:00  20      10
103713     8/12/2011 0:00  23      10

notice i have 2 inputs for day 5/12/2011 but the results of the query are

quantity   hour    date
10         23      8/12/2011 0:00
10         20      6/12/2011 0:00
11         20      5/12/2011 0:00
10         14      4/12/2011 0:00

one input is missing.

  • 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-05-27T10:48:20+00:00Added an answer on May 27, 2026 at 10:48 am

    The below one should work.

    SELECT * 
    FROM `13_trans_coffee`
    WHERE  `Site Code` =103713 AND `Date` 
    IN
    (
    SELECT `Date`
    FROM `13_trans_coffee`
    WHERE `Site Code` =103713
    GROUP BY `Date`
    ORDER BY `Date` DESC
    LIMIT 0 , 7
    ) Z;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table USERS with the following fields date(datetime) email(varchar) provider(int) event(int) I
I have a table with the following fields: Action => Click/Open DateTime => Date
I have a table, 'lasttraces', with the following fields. Id, AccountId, Version, DownloadNo, Date
So, I have a database table with the following fields: title , date ,
I have a large table with the following fields: Date Product_ID AmountEUR_Field1 AmountEUR_Field2 AmountEUR_Field3
I have one table called: Transaction. This table has the following fields: (ID,ProductName,Amount,Date) placed
I have a table Sales with the following fields: code, amount, index, name .
I have a table called Employee with the following fields: EmpID Salary Name I
I have a table in db2 which has the following fields int xyz; string
I have a table (session_comments) with the following fields structure: student_id (foreign key to

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.