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

  • Home
  • SEARCH
  • 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 5997987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:20:30+00:00 2026-05-23T00:20:30+00:00

I have the following MySQL. SELECT `outputtable`.`date`, count(*) as `count` FROM ( SELECT CONCAT(DATE(`mytable`.`starttime`),’

  • 0

I have the following MySQL.

    SELECT
        `outputtable`.`date`,
        count(*) as `count`
    FROM (
        SELECT
            CONCAT(DATE(`mytable`.`starttime`),' ',HOUR(`mytable`.`starttime`),':',LPAD(10*(MINUTE(`mytable`.`starttime`) DIV 10),2,'0')) as `date`,
            `mytable`.`clientid`
        FROM
            `mytable`
        WHERE
            `mytable`.`clientid`='1'
        GROUP BY
            `mytable`.`clientid`
        ORDER BY 
            `date`
        ) AS outputtable
    GROUP BY
        `date`
    ORDER BY
        `date` ASC

The outputted date field does not order correctly according to datetime ordering rules.

Example of how the output is ordered:

2011-02-01 17:00 | 4

2011-02-01 18:00 | 1

2011-02-01 19:00 | 1

2011-02-01 21:00 | 1

2011-02-01 8:00 | 6

2011-02-01 9:00 | 7

I presume that this is because the newly created field named ‘date’ is a varchar.

How do I set the type to ‘Datetime’ for the field ‘date’ in the table ‘outputtable’, so that it orders correctly?

Thanks in advance,

H.

  • 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-23T00:20:31+00:00Added an answer on May 23, 2026 at 12:20 am

    Cast it to date, like this:

    cast(CONCAT(DATE(`mytable`.`starttime`),' ',HOUR(`mytable`.`starttime`),':',LPAD(10*(MINUTE(`mytable`.`starttime`) DIV 10),2,'0')) as DATE) as date
    

    or more readably:

     SELECT
        cast(`outputtable`.`date` as date),
        count(*) as `count`
     -- the rest of the query the same
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At the moment I have the following MySQL query: SELECT COUNT(*) AS `count`, `v`.`value`
I have a problem with the following MySQL query: SELECT * FROM TPDSessions WHERE
Basically I have a mysql query something like the following: mysql_query(SELECT n.title, v.value FROM
I have the following MySQL query and tables from which I am querying: SELECT
I have the following table: mysql> SELECT * FROM temp; +----+------+ | id |
I have the following query in mysql 5.1.41: select distinct table_schema from information_schema.tables where
I have a little problem, have the following statement in mysql: SELECT cmfilm.*, cmgenre.titel
I have following query on a MySQL DB: SELECT * , r.id, x.real_name AS
I have an application that executes the following MySQL query: SELECT 402 AS user_id,
I have the following MySQL Query: <div class=box id=settlement1> <? $query = SELECT name,

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.