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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:09:22+00:00 2026-06-14T05:09:22+00:00

I have a table that tracks tags users create. The important columns for this

  • 0

I have a table that tracks tags users create. The important columns for this question, I believe, would be user_id (of who made the tag) and created_at.

With some searching I found how to use date_trunc to turn created_at into just a day so that we can group by that.

However, I can only get this to give me the count of total tags for a day. What I want to do is group by both user and day, such that I can see how many tags each user created each day, and with some ordering figure out what the most number of tags a user has created in a day ever is.

I’m using postgres 9.1.6.

Any help? Thanks in advance.

EDIT: What I have started with, mainly a shot in the dark, is:

select user_id,
       date_trunc('day', created_at) as "Day",
       count(*) as "numtags"
  from tags
  group by user_id, created_at
  order by numtags desc;

And the result is:

 user_id |         Day         | numtags 
---------+---------------------+---------
      1  | 2012-01-08 00:00:00 |    5719
      1  | 2012-01-31 00:00:00 |    3239
      1  | 2011-12-01 00:00:00 |    1868
      1  | 2011-12-01 00:00:00 |    1772
      1  | 2011-12-01 00:00:00 |    1756

So clearly the grouping isn’t working as desired, the user IDs are all the same (which I have confirmed manually they should not be).

I would like to see something like (numbers don’t match above, just an example):

 user_id |         Day         | numtags 
---------+---------------------+---------
      1  | 2012-01-08 00:00:00 |    100
      4  | 2012-01-31 00:00:00 |    90
      1  | 2011-12-12 00:00:00 |    80
      2  | 2011-12-12 00:00:00 |    77
      2  | 2011-12-13 00:00:00 |    76

i.e. The same user will appear many times, the same date will appear many times – in fact every user_id/Day combination will show up (once each) as long as the user made at least one tag on a day, and numtags will show how many tags were made by that user on that day.

  • 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-14T05:09:23+00:00Added an answer on June 14, 2026 at 5:09 am

    As I suggested:

    select user_id,
       created_at::date as "Day",
       count(*) as "numtags"
    from tags
    group by user_id, created_at::date
    order by numtags desc;
    

    created_at::date is casting timestamp to date type.

    Your mistake was to group by createdate which is timestamp with different time part but in result you had truncated timestamp.

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

Sidebar

Related Questions

I have a table that looks like this: CREATE TABLE foobar ( id SERIAL
I have this big database table that tracks (currently in production), a persons medical
I have a table that tracks attendance in a course. The columns are the
I have a very basic mysql table called memberships, that tracks which people belong
I have a table that looks like this: id value AGA 0.211 AGA 0.433
I have a table that tracks serial numbers and the number of licenses associated
I'm working in Sql Server 2005. I have an event log table that tracks
I have a table that tracks user interactions with a customer’s record. I want
So I have a table that tracks the updating of a projects status. Now
I have a table (tbl_MatterItem) in my DB that tracks the dates that items

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.