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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:39:09+00:00 2026-05-27T02:39:09+00:00

I have 3 tables: user_transaction, transaction and users I am trying to create a

  • 0

I have 3 tables: user_transaction, transaction and users

I am trying to create a summary table of distinct transactions
on a each date basis
for each employee
for each resource

as follows: (filtering datetime to date using format specifier)

select 
  count(distinct(user_transaction.trans_id)) as obj, 
  DATE_FORMAT(DATE, '%Y-%m-%d') as tdate
from 
  user_transaction, transaction,users 
where 
  users.id = user_transaction.user_id 
  and users.employeeid = 'samuel' 
  and user_transaction.trans_id=transaction.id  
  and resource_id =1 and transactiontext like '%<-->%' 
  and DATE_FORMAT(user_transaction.date,'%Y-%m-%d') 
    between '2011-08-30' and '2011-11-28'
  group by 
    DATE_FORMAT(user_transaction.DATE, '%Y-%m-%d')

result of the above query is I get distinct transaction count for user ‘samuel’ on each date in the range

e.g. 2011-08-30…………22;
2011-09-01…………431;
2011-09-03…………64 ;
etc..

now I sum up all these values I get a count like total for the user : 1486

This count is not matching up with my modified query for the same user and date range if I do a direct count without the group by on Date field.
i.e. If I run the query below without date grouping :

select 
  count(distinct(user_transaction.trans_id)) as obj, 
from 
  user_transaction, transaction,users 
where 
  users.id = user_transaction.user_id and users.employeeid = 'samuel' 
  and user_transaction.trans_id=transaction.id  
  and resource_id =1 and transactiontext like '%<-->%' 
  and DATE_FORMAT(user_transaction.date,'%Y-%m-%d') 
    between '2011-08-30' and '2011-11-28'

This gives me a count like 1452,
the count over the range with date grouping and summing it to get total is generally more for every user, not sure why.

I need to have the counts calculated for each date for my summary table.

The count I get directly without using the group by clause is correct, checked it in the table.

What exactly am I doing wrong in the group by clause?

  • 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-27T02:39:09+00:00Added an answer on May 27, 2026 at 2:39 am

    Since you are counting the distinct values and grouping by date, it may be possible that you have the same trans_id on multiple days, thus giving you a greater count in the query with the group by than that without.

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

Sidebar

Related Questions

Here's the scenario: I have 2 tables: CREATE TABLE dbo.API_User ( id int NOT
I have 3 tables users(id,name),groups(id,name) and users_groups(user_id,group_id). users and groups have many to many
I have 3 tables: users (id, name) currency (id, name) accounts (id, user_id, currency_id,
I have two tables: Users: ID, first_name, last_name Networks: user_id, friend_id, status I want
i have an SQL statement wherein i am trying to update the table on
I'm trying to run a query on a table that we keep for transactions
I have two tables Employee (EmpID, Name, UpdatedBy, UpdateDate) EmpContact (ContactID, Contact,EmpID) I am
we have a ASP.NET site with a SQL2008 DB. I'm trying to implement transactions
I have three tables: User: UserId (pk) FirstName Lastname Messages: MessageId (pk) Heading Body
I have 2 tables - one storing user information (id, username, password) and the

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.