Koenman Koenman - 7 months ago 24
SQL Question

Mysql only WHERE LIKE on month

let's say i have this query:

SELECT COUNT(datum) FROM unique_ip WHERE (datum>='2016-02-01' AND datum<='2016-02-29')


I want to do a WHERE LIKE so only the month has to be specific like 01, 02 etc. So my query is only looking for this: ____-02-__ . How can i use WHERE LIKE in this case?

This is my Database scheme:


  • ip - INT UNSIGNED - PK NOT NULL

  • datum - DATE - NOT NULL (datum means date)

  • Telling - INT - NOT NULL DEFAULT = 1 (Telling meaning counting)



i'd be glad to supply you with more information if needed.

Answer

You can use the MONTH() function or something like SELECT COUNT(datum) FROM unique_ip WHERE datum LIKE '%-02-%';.