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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:14:31+00:00 2026-06-18T18:14:31+00:00

i have one table name as a_ad_display with following column displayId | campaignId |

  • 0

i have one table name as a_ad_display with following column

displayId | campaignId | displaytime(date)

1          |    2      | 2012-12-19 12:41:08
2          |    2      | 2012-12-19 01:41:08
3          |    1      | 2012-12-20 10:41:08
4          |    1      | 2012-12-20 02:41:08
5          |    1      | 2012-12-21 12:41:08
6          |    2      | 2012-12-21 01:41:08
7          |    1      | 2012-12-21 12:41:08
8          |    1      | 2012-12-21 02:41:08

there is a multiple entry with same campaignId should be there.now what i want is to first of all fetch the campaignId with the highest count in a_ad_display and for that campaignId i want to get total number of count within the date

eg..from above table i have 1 number campaignId with highest row count

so for 1 number campaignId i want to display records like this..

        **Date**     | **countPerDay**
 2012-12-19          |      0
 2012-12-20          |      2
 2012-12-21          |      3

how can i achieve this in mysql database…hope anyone can guide me…

  • 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-18T18:14:32+00:00Added an answer on June 18, 2026 at 6:14 pm

    You can use this query

    select 
        count(campaignId) as TCount,
        DATE(displayTime) as `Date`
    from a_ad_display
    where campaignId = 1
    group by DATE(displayTime)
    

    Although it will not display 0.

    EDIT :

    OK This is modified and fetches your result.

    select
      date(a.displayTime) as `DisplayTime`,
      ifnull(l.TCount,0) as TCount
    from a_ad_display as a
      left join (select
               count(campaignId) as TCount,
               displayTime
             from a_ad_display
             where campaignId = 1
             group by DATE(displayTime)) as l
        on date(a.displayTime) = date(l.displayTime)
    group by DATE(a.displayTime)
    

    Demo

    MORE EDITS :

    select
      date(a.displayTime) as `DisplayTime`,
      ifnull(l.TCount,0) as TCount
    from a_ad_display as a
      left join (select
               count(campaignId) as TCount,
               displayTime
             from a_ad_display
             where campaignId = 1
             group by DATE(displayTime)) as l
        on date(a.displayTime) = date(l.displayTime)
    group by DATE(a.displayTime)
    order by a.displaytime desc limit 5
    

    This is how you can select latest 5 records. If you want to select the latest campaign you can use a subquery instead of 1 take a look at this query

    select
      date(a.displayTime) as `DisplayTime`,
      ifnull(l.TCount,0) as TCount
    from a_ad_display as a
      left join (select
           count(campaignId) as TCount,
           displayTime
         from a_ad_display
         where campaignId = (select  campaignId from a_ad_display group by campaignId order by count(campaignId) desc limit 1)
         group by DATE(displayTime)) as l
        on date(a.displayTime) = date(l.displayTime)
    group by DATE(a.displayTime)
    

    EDITS :

    I have edited the query this will fetch higher occurance campaignId and fetch results accordingly

    Demo

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

Sidebar

Related Questions

I have one main table MainTable ( ID, Name ) The Name column contains
I have one table with name CateringPurchaseOrder. That table contains one column with name
I have a database with many tables and one particular table has columns: name
I have a table student ( id, name ). Then I have one textbox,
i have a table like this one: -------------------------------- id | name -------------------------------- 1 |
i have one table TABLE_SUBJECT And i pass subject name to DBHelper.java. Then i
Hi every one I have these classe @Entity @Table(name = login, uniqueConstraints={@UniqueConstraint(columnNames={username_fk})}) public class
I have two tables one with ID and NAME table 1 ID | NAME
Quick method description: I have two tables, lets name them table ONE and table
i have one table with a single column having three values a,b and c.

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.