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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:12:28+00:00 2026-05-18T11:12:28+00:00

I am running this query: SELECT u.id as id, COUNT(DISTINCT YEAR(TIMESTAMP), WEEK(TIMESTAMP)) cc, GROUP_CONCAT(DISTINCT

  • 0

I am running this query:

SELECT u.id as id, 
       COUNT(DISTINCT YEAR(TIMESTAMP), WEEK(TIMESTAMP)) cc, 
       GROUP_CONCAT(DISTINCT YEAR(TIMESTAMP),'-',WEEK(TIMESTAMP)) a
FROM   users u 
       JOIN checkins c 
         ON c.userid = u.id 
GROUP  BY userid
HAVING COUNT(cc) = 3

And this produces the following results:

id  cc  a
05  3   2010-43,2010-47,2010-45 
06  2   2010-44,2010-45 
13  3   2010-43,2010-45,2010-48 
20  3   2010-45,2010-43,2010-47 
21  3   2010-43,2010-47,2010-45 
22  2   2010-47,2010-48 
25  3   2010-48,2010-43,2010-46 
27  2   2010-42,2010-47 
30  2   2010-48,2010-45 
41  3   2010-44,2010-45,2010-47 
44  2   2010-42,2010-44 
50  2   2010-44,2010-47 
52  2   2010-48,2010-47 
57  2   2010-43,2010-44 
71  3   2010-43,2010-48,2010-47 
72  2   2010-43,2010-44 
78  3   2010-47,2010-42,2010-43 
79  2   2010-45,2010-46 
80  2   2010-46,2010-44 
87  1   2010-46 
97  1   2010-48 
108 3   2010-43,2010-47,2010-45 

As you see the cc column has values 2, 3, or even 1.

How that comes, when I’ve told with HAVING that should be 3?

  • 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-18T11:12:29+00:00Added an answer on May 18, 2026 at 11:12 am

    MySQL does allow aliases in the Having clause. You would need to use:

    HAVING cc = 3
    

    not

    HAVING COUNT(cc) = 3
    

    in order to filter the results to only include rows which have a cc value of 3 though. I’m actually quite unsure though why HAVING COUNT(cc) = 3 would return any results at all.

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

Sidebar

Related Questions

I'm running a query which looks like this SELECT parent.field, child.field FROM parent JOIN
I'm running a query that looks like this: $results = $DB2->query(SELECT COUNT(*) FROM auth_user
Please consider the following query: SELECT artist.id, COUNT(DISTINCT artist$styles.v_id) FROM artist LEFT JOIN artist$styles
I'm running this query on an Oracle DB: SELECT COUNT(1) FROM db.table WHERE columnA
I'm running this query: SELECT TOP 1 [DVD Copy].[Stock No] FROM [DVD Copy] WHERE
Running this query takes a long time: SELECT host,ip FROM arecords WHERE ip IN
After running this query statement with my database: select * from articles where content
I'm new to MySQL, and I'm running this query, SELECT item_id,amount FROM db.invoice_line WHERE
I have this MySQL query: SELECT DAYOFYEAR(`date`) AS d, COUNT(*) FROM `orders` WHERE `hasPaid`
I have this query in my sql if (select count(*) from sys.columns where object_id

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.