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

  • Home
  • SEARCH
  • 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 8170649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:11:38+00:00 2026-06-06T21:11:38+00:00

The task is a grouping of datetime values (using SQLAlchemy) into per minute points

  • 0

The task is a grouping of datetime values (using SQLAlchemy) into per minute points (group by minute).

I have a custom SQL-query:

SELECT COUNT(*) AS point_value, MAX(time) as time
  FROM `Downloads` 
  LEFT JOIN Mirror ON Downloads.mirror = Mirror.id 
 WHERE Mirror.domain_name = 'localhost.local' 
   AND `time` BETWEEN '2012-06-30 00:29:00' AND '2012-07-01 00:29:00'
 GROUP BY DAYOFYEAR( time ) , ( 60 * HOUR( time ) + MINUTE(time ))
 ORDER BY time ASC

It works great, but now I have do it in SQLAlchemy. This is what I’ve got for now (grouping by year is just an example):

rows = (DBSession.query(func.count(Download.id), func.max(Download.time)).
    filter(Download.time >= fromInterval).
    filter(Download.time <= untilInterval).
    join(Mirror,Download.mirror==Mirror.id).
    group_by(func.year(Download.time)).
    order_by(Download.time)
)

It gives me this SQL:

SELECT count("Downloads".id) AS count_1, max("Downloads".time) AS max_1 
FROM "Downloads" JOIN "Mirror" ON "Downloads".mirror = "Mirror".id 
WHERE "Downloads".time >= :time_1 AND "Downloads".time <= :time_2 
GROUP BY year("Downloads".time) 
ORDER BY "Downloads".time

As you can see, it lacking only the correct grouping:

GROUP BY DAYOFYEAR( time ) , ( 60 * HOUR( time ) + MINUTE(time ))

Does SQLAlchemy have some function to group by minute?

  • 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-06T21:11:40+00:00Added an answer on June 6, 2026 at 9:11 pm

    You can use any SQL side function from SA by means of Functions, which you already use fr the YEAR part. I think in your case you just need to add (not tested):

    from sqlalchemy.sql import func
    ...
    # add another group_by to your existing query:
    rows = ...
    group_by(func.year(Download.time), 
             60 * func.HOUR(Download.time) + func.MINUTE(Download.time)
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the task I want to achieve is import XML file into SQL Server. Once
Task: Write timestamps into MS SQL database table every second. Solutions: External application which
I have the following Linq to SQL query, in which I'm trying to do
Task at hand — I have three versions of some code, developed by different
TASK : I have an existing xml document (UTF-8) which uses xml namespaces and
Task: I have a camera mounted on the end of our assembly line, which
UPDATE Some answers so far have suggested using an adjacency list. How would an
Task: to build hash using map, where keys are the elements of the given
Task: Cut or erase a file after first walk-through. i have an install file
Task is: I have task queue stored in db. It grows. I need 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.