MySQL Multiple counts in one query with case

前端 未结 2 680
遥遥无期
遥遥无期 2021-01-29 06:18

Good day,

I have compiled the following query.

SELECT
    COUNT(CASE WHEN `booking_creationdate` LIKE \'2020-01-31%\' THEN 1 END) AS 2020-01-31,
    COUN         


        
相关标签:
2条回答
  • 2021-01-29 07:04

    I guess there is problem with quotes in query : Try below:

    SELECT
        COUNT(CASE WHEN booking_creationdate LIKE '2020-01-31%' THEN 1 END) AS "2020-01-31",
        COUNT(CASE WHEN booking_creationdate LIKE '2020-02-05%' THEN 1 END) AS "2020-02-05"
    FROM bookingstable AND booking_location = 4
    
    0 讨论(0)
  • 2021-01-29 07:07

    - isn't allowed in identifiers unless the identifier is enclosed in back ticks. So instead of

    ... AS 2020-01-31
    

    write

    ... AS `2020-01-31`
    

    and analog for all other cases. Or use another alias without -.

    Side note: It seems like booking_creationdate is a string. That's the wrong data type. Use some date/time data type.

    0 讨论(0)
提交回复
热议问题