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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:15:11+00:00 2026-06-03T11:15:11+00:00

I have a simple referrers table with three columns: Referrer //string name of partner

  • 0

I have a simple referrers table with three columns:

Referrer    //string name of partner
TimeOfVisit //timestamp
SessionID   //(unique id only used when joining with sales data for conversion)

I would like to retrieve data for analytics, and present a stacked column chart, with a column for each day showing the referrer sources for visitors.

This is the query that I managed to put together:

SELECT
    DATE(TimeOfVisit) AS Date,
    Referrer,
    COUNT(Referrer) AS VisitorCount
FROM referrers
GROUP BY CONCAT(DATE(time_of_visit), referrer)

It does kind of give me the data I am looking for:

Array
(
    [0] => Array
        (
            [Date] => 2012-04-01
            [Referrer] => adwords
            [VisitorCount] => 3
        )

    [1] => Array
        (
            [Date] => 2012-04-01
            [Referrer] => facebook
            [VisitorCount] => 5
        )

    [2] => Array
        (
            [Date] => 2012-04-02
            [Referrer] => adwords
            [VisitorCount] => 6
        )
...

I have two problems with this:

  1. Even I can feel it, that grouping by a concatenated string is hideous, it just does not feel right.
  2. The php script parsing the result will always need to know the full list of current referrers, so it can assign a 0 value in case there were no clicks from a refferer on a given day. Not very elegant, to say the least.

What is the most effective way to solve this problem? Could it actually be solved in MySQL only?

  • 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-03T11:15:12+00:00Added an answer on June 3, 2026 at 11:15 am

    You can just GROUP BY Date, Referrer

    The MySQL results will have “gaps”, periods in which certain referrers will have 0 hits.

    Assuming you’re colouring the referrers (not sure how many you have) and you wish to have a consistent colour for each, you could calculate a numeric hash and use that as an index over a predefined array of colours.

    Not sure whether I’ve addressed all your questions or if you understood all of my answer, but just shout 🙂

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

Sidebar

Related Questions

I have simple static lib in xcode with the only class test.h: @interface TestClass
I have simple form. <form target=_blank action=somescript.php method=Post id=simpleForm> <input type=hidden name=url value=http://...> <input
Let's say I have a simple class Cat in C#, with a Name property
I have a simple Django model like: class Person(models.Model): referrer = models.ForeignKey('self', null=True) ...
I have simple list: <ul> <li>some text 1 </li> <li>some text 2</li> <li>some text
I have simple regex \.*\ for me its says select everything between and ,
I have simple win service, that executes few tasks periodically. How should I pass
i have simple regular expression: ^123$ Matches are for example 123 1234 etc. How
I have simple issue setting a two-way databinding of a checkbox in Silverlight 3.0.
I have simple SSIS package which reads data from flat file and insert into

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.