我正在尝试从看起来像“2008-08-17 00:00:00”的日期中提取月份

I'm trying to extract month from date which looks like this "2008-08-17 00:00:00"

这是一个示例,我正在尝试合并两个表格,如您所见,db_match 和国家/地区,但我需要从整个日期中提取月份,所以我可以在这里尝试什么?

我试过了,

update db_match set date=str_to_date(date,"%Y/%m/%d %h:%i:%s");

这是连接查询:

select db_match.date,country.name,country.id
from db_match(
select EXTRACT (MONTH FROM date) as Themonth
)sub
inner join country
on country.id=db_match.country_id

group by Themonth
order by id;

使用MONTH()
注意:您已标记 mySQL,这在 mySQL 中有效吗?我现在没有qsqldatabase.

SELECT MONTH('2008-08-17 00:00:00') "month"

returns 8
您的查询变成如下所示。没有您的 table 描述和示例数据,我无法对其进行测试。

SELECT
  MONTH(d.date) "Month",
  c.name Country,
  c.id Code
FROM 
  db_match d 
JOIN
  county c on d.country_id = c.id
GROUP BY 
  MONTH(d.date),
  c.name,
  c.id;