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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:37:29+00:00 2026-06-04T01:37:29+00:00

first question, hoping someone can help here. I’ve been trying to track down how

  • 0

first question, hoping someone can help here. I’ve been trying to track down how to do this for a bit and figured it was time to ask for an assist. Please note I’m very new to My SQL queries and my code is probably as inelegant as it gets!

I’m working with two databases with identical configurations. Each database represents regional data but all tables and columns are identical between them. In essence I’m looking to get a daily count of activities performed by a specific individual. Also, the data I need to gather is on multiple tables so bear with me s I make my notations here: D_USA and D_CAN for the two databases, T1 and T2 for the two tables I’m joining. Here is my existing code and the output I get:

SELECT 
  "USA" AS REGION, 
  LEFT(FROM_UNIXTIME(D_USA.T1.date),10) as DATE,
  D_USA.T1.owner AS OWNER, COUNT(DISTINCT D_USA.T1.id) AS GROUPS, 
  COUNT(DISTINCT D_USA.T2.id) AS UNITS
FROM
  D_USA.T1
  JOIN D_USA.T2 ON D_USA.T1.id = D_USA.T2.parent_id
WHERE
  D_USA.T1.complete='Y'
  AND D_USA.T1.owner = 'XYZ' 
  AND D_USA.T2.status = 'P' 
  AND LEFT(FROM_UNIXTIME(D_USA.T1.date),10) >= '2012-01-01'
GROUP BY DATE
UNION ALL
SELECT 
  "CAN" AS REGION, 
  LEFT(FROM_UNIXTIME(D_CAN.T1.date),10) as DATE,
  D_CAN.T1.owner AS OWNER, 
  COUNT(DISTINCT D_CAN.T1.id) AS GROUPS, 
  COUNT(DISTINCT D_CAN.T2.id) AS UNITS
FROM
  D_CAN.T1
  JOIN D_CAN.T2 ON D_CAN.T1.id = D_CAN.T2.parent_id
WHERE 
  D_CAN.T1.complete='Y'
  AND D_CAN.T1.owner = 'XYZ' 
  AND D_CAN.T2.status = 'P' 
  AND LEFT(FROM_UNIXTIME(D_CAN.T1.date),10) >= '2012-01-01'
GROUP BY DATE 
ORDER BY DATE ASC;

Current Output:

REGION|DATE|OWNER|GROUPS|UNITS
USA|2012-01-01|XYZ|10|100
CAN|2012-01-01|XYZ|5|100
USA|2012-01-02|XYZ|10|75
USA|2012-01-03|XYZ|5|50
CAN|2012-01-03|XYZ|10|50
CAN|2012-01-04|XYZ|10|100

Desired Output (based on above)

DATE|OWNER|GROUPS|UNITS
2012-01-01|XYZ|15|200
2012-01-02|XYZ|10|75
2012-01-03|XYZ|15|100
2012-01-04|XYZ|10|100

Any assistance will be greatly appreciated!

  • 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-04T01:37:31+00:00Added an answer on June 4, 2026 at 1:37 am

    Just wrap a select round it as in

    Select Date,Owner,Groups, Sum(Units) as Units
    From (insert your query in here) somedummyName
    Group By Date,Owner,Groups

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

Sidebar

Related Questions

This question is a little specific and I am hoping someone here can shed
As a follow-up to this question I am hoping someone can help with the
Apologies if this question has been asked before. I'm hoping that someone can step
I can't find an answer to this question anywhere so I'm hoping someone can
This question actually has two parts. The first part: I've been developing my first
I have a weird problem that I am hoping someone can help me with.
I am new to iPhone programming so am hoping someone can help me out
I was hoping someone could help a noobie out. I am trying to create
First question here, and yes this is a homework question. We are tasked with
I'm really stuck with a problem I'm hoping someone can help me with. I'm

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.