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 table in Sybase -- Creating table 'SimpleText' CREATE TABLE [dbo].[SimpleText] (
I have simple database - one table with 6 collumns. 3 of them i
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 product_details table which belongs to categories. product_details has fields like id, name,
I have a simple Django model like: class Person(models.Model): referrer = models.ForeignKey('self', null=True) ...
I have simple class with width and height member fields which define number of
I have simple php validation form that is halfway working. If you leave the
I have simple JavaScript snippet: var obrazek = [{nazwa: "Sniadanie", wiek: 100, autor: "Alicja"},{nazwa:
I have simple script with EventMachine, Fibers and faye require faye require em-synchrony require

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.