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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:07:53+00:00 2026-05-19T05:07:53+00:00

I have the following MySQL query, and I’m trying to adjust it so it

  • 0

I have the following MySQL query, and I’m trying to adjust it so it only fetches results which are within the current month (of the current year), I’m guessing you may require more info about my MySQL structure so here it goes – I have a UNIX timestamp generated by PHP’s time() stored within the time column (under the referrals table), so with the below setup it would be t2.time.

So my problem is I’m unsure how to proceed, I’m guessing it would be something like adding the following to end of the WHERE clause? => AND t2.time IS WITHIN THE CURRENT MONTH (caps are just on to distinguish problem from rest of query) but i’m not sure how to check if its within the current month.

The MySQL Query:

SELECT t1.username,
       t1.website,
       SUM(IF(t2.type = 'in', 1, 0))  AS in_count,
       SUM(IF(t2.type = 'out', 1, 0)) AS out_count
FROM   users AS t1
       JOIN referrals AS t2
         ON t1.username = t2.author
WHERE  t1.website != ''
GROUP  BY t1.username,
          t1.website
ORDER  BY in_count DESC 
LIMIT  0, 10 

Appreciate all help! :B

  • 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-19T05:07:54+00:00Added an answer on May 19, 2026 at 5:07 am

    you can use from_unixtime like

    date_format(from_unixtime(t2.`time`), '%Y-%m')=date_format(now(), '%Y-%m')
    

    But I think data type integer is not so suitable for this requirement

    I would think using datetime will be more suitable, built an index on this column and this also make the filtering easier, like

    t2.`time`>='2011-01-01' and t2.`time`<'2011-02-01'
    

    or

    date_format(t2.`time`, '%Y-%m')=date_format(now(), '%Y-%m')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following mysql query, which is producing a list of entries by
I have the following mysql query which I am running with php like so.
I currently have the following MySQL query, which I would like to include in
I have the following mysql query which is taking about 3 minutes to run.
I have the following MYSQL query which when executed shows me all the invalid
I have the following MySQL query, which produces the result I want: SELECT `l`.`status`,
I currently have the following MySQL query, which executes fine without any errors: SELECT
I have the following MySQL query that I'm trying to translate into an equivalent
I have the following MySQL query, which I'm using with PHP (5.2). DELETE t1.*,
I have the following MySQL query which gets all the bookings for an agent,

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.