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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:56:40+00:00 2026-05-11T19:56:40+00:00

OK I have this query that groups 2 columns together quite nicely: SELECT search_query_keyword,

  • 0

OK I have this query that groups 2 columns together quite nicely:

SELECT search_query_keyword, search_query_date, COUNT(1) as count
            FROM search_queries 
            WHERE search_query_date >= '.$from.' AND search_query_date <= '.$to.'
            GROUP BY search_query_keyword, search_query_date
            ORDER BY count DESC
            LIMIT 10

But what if I want to group by a date RANGE instead of just a date? Is there a way to do that?

Thanks!

EDIT: OK these answers are pretty complicated and I think what I want can be acheived a lot easier so let me re-explain. I want to select keywords over a time period “>= 20090601 AND <= 20090604” for example. But instead of getting repeated keywords I would rather just get the keyword ounce and how many times it occured. So for example instead of this:

keyword: foo
keyword: foo
keyword: foo
keyword: bar
keyword: bar

I would get:

keyword: foo, count: 3
keyword: bar, count: 2
  • 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-11T19:56:40+00:00Added an answer on May 11, 2026 at 7:56 pm

    I’m not exactly sure about the date range grouping — you’d have to define the date ranging that you would want and then maybe you could UNION those queries:

    SELECT 
        'Range 1' AS 'date_range',
        search_query_keyword
    FROM search_queries
    WHERE search_query_date >= '.$fromRange1.' AND search_query_date <= '.$toRange1.'
    UNION
    SELECT 
        'Range 2' AS 'date_range',
        search_query_keyword
    FROM search_queries
    WHERE search_query_date >= '.$fromRange2.' AND search_query_date <= '.$toRange2.'
    GROUP BY 1,2
    

    Or if you wanted to put them within a grouping of how many days old like “30 days, 60 days, etc” you could do this:

    SELECT 
        (DATEDIFF(search_query_date, NOW()) / 30) AS date_group,
        search_query_keyword
    FROM search_queries
    GROUP BY date_group, search_query_keyword
    

    EDIT: Based on the further information you provided, this query should produce what you want:

    SELECT 
        search_query_keyword,
        COUNT(search_query_keyword) AS keyword_count
    FROM search_queries
    WHERE search_query_date >= '.$from.' AND search_query_date <= '.$to.'
    GROUP BY search_query_keyword
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright. I have a query that looks like this: SELECT SUM(`order_items`.`quantity`) as `count`, `menu_items`.`name`
Alright, so I have a query that looks like this: SELECT `orders`.*, GROUP_CONCAT( CONCAT(
I have a query that originally looks like this: select c.Id, c.Name, c.CountryCode, c.CustomerNumber,
I have this query: SELECT page.id, revision.title, revision.number FROM page INNER JOIN revision ON
I have this SQL query: SELECT * FROM IMAGES WHERE IMAGENAME in ('IMG1', 'IMG2',
I have a query that groups all entries from a table and groups them
I have this sql query retrieving IDs from a table with 3 columns: ID,
I have this query statement and want to only get records that has a
I have a query that looks like this: public IList<Post> FetchLatestOrders(int pageIndex, int recordCount)
I have this query in sql server 2000: select pwdencrypt('AAAA') which outputs an encrypted

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.