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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:28:44+00:00 2026-06-14T12:28:44+00:00

I have a database (MySQL 5.5) similar to this: ID Name Page Visited Date

  • 0

I have a database (MySQL 5.5) similar to this:

ID    Name   Page Visited   Date
1     Tim     Page A         11-2-2000
1     Tim     Page B         11-3-2000
1     Tim     Page B         11-3-2000
2     Jeff    Page C         11-5-2000
2     Jeff    Page A         11-11-2000

I want to build a query (trying to at the moment), where the results would be similar to this:

ID    Name    Page A Visits  Page B Visits  Page C Visits
1     Tim          1             2               0

I assume that I need to run the following query against a subset (my question is how do I do this with essentially 3 counts)?:

SELECT * From database.mytable GROUP BY ID HAVING COUNT(*) >=1
  • 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-14T12:28:45+00:00Added an answer on June 14, 2026 at 12:28 pm
    SELECT ID, Name,
            SUM(CASE WHEN `Page Visited` = 'Page A' THEN 1 ELSE 0 END) `Page A Visit`,
            SUM(CASE WHEN `Page Visited` = 'Page B' THEN 1 ELSE 0 END) `Page B Visit`,
            SUM(CASE WHEN `Page Visited` = 'Page C' THEN 1 ELSE 0 END) `Page C Visit`
    FROM tableName
    GROUP BY ID, Name
    
    • SQLFiddle Demo

    if you have unknown number of page, you can also PreparedStatement

    SET @sql = NULL;
    SELECT
      GROUP_CONCAT(DISTINCT
        CONCAT(
          'SUM(CASE WHEN `Page Visited` =''',
          `Page Visited`,
          ''' then 1 ELSE 0 end) AS ',
          CONCAT('`',`Page Visited`, ' Visits`')
        )
      ) INTO @sql
    FROM TableName;
    
    SET @sql = CONCAT('SELECT ID, Name, ', @sql, ' 
                       FROM tableName
                       GROUP BY ID, Name');
    
    PREPARE stmt FROM @sql;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;
    
    • SQLFiddle Demo
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL database that looks similar to this: ID Group Name 1
I have a few tables in a MySQL database similar to this setup: major
I have mysql database like this id | code 1 | bok-1 2 |
I have mysql database and I want a software which can draw the database
I have a MySQL database table called Participant that looks something like this: (idParticipant)
I want to query a table in a mysql database and display the results
I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
I have a database in MySQL which have entries of time. There are more
So I have a database for a forum board, stored in a MySQL database
I have a MySQL database where the table was set up to store the

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.