MySQL Multiple counts in one query with case

前端 未结 2 681
遥遥无期
遥遥无期 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: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.

提交回复
热议问题