相关疑难解决方法(0)

如何获取mysql中每个相应月份的第一天?

我想获得当年每个月的第一天.例如,如果用户选择"2010-06-15",则查询要求从"2010-06-01"而不是"2010-06-15"运行.

请帮我如何计算所选日期的第一天.目前,我正在尝试使用以下mysql选择查询:

Select
  DAYOFMONTH(hrm_attendanceregister.Date) >=
  DAYOFMONTH(
    DATE_SUB('2010-07-17', INTERVAL - DAYOFMONTH('2010-07-17') + 1 DAY
  )
FROM
  hrm_attendanceregister;
Run Code Online (Sandbox Code Playgroud)

谢谢

mysql date

38
推荐指数
6
解决办法
5万
查看次数

如何在mysql中获取一周中第一天的第一天?

假设我有2011-01-03并且我想获得本周的第一周,这是星期日,即2011-01-02,我该怎么做呢?

原因是我有这个查询:

select 
  YEAR(date_entered) as year, 
  date(date_entered) as week,   <-------This is what I want to change to select the first day of the week.
  SUM(1) as total_ncrs, 
  SUM(case when orgin = picked_up_at then 1 else 0 end) as ncrs_caught_at_station 
from sugarcrm2.ncr_ncr 
where 
sugarcrm2.ncr_ncr.date_entered > date('2011-01-01') 
and orgin in( 
'Silkscreen', 
'Brake', 
'Assembly', 
'Welding', 
'Machining', 
'2000W Laser', 
'Paint Booth 1', 
'Paint Prep', 
'Packaging', 
'PEM', 
'Deburr', 
'Laser ', 
'Paint Booth 2', 
'Toolpath' 
) 
and date_entered is not null 
and orgin is not null …
Run Code Online (Sandbox Code Playgroud)

mysql time select date

20
推荐指数
5
解决办法
6万
查看次数

MySQL查询返回月份列表

如果表具有这种结构,有没有办法获得几个月的列表:

Table
id    | payment  | date
1001    200.00     2013-10-11
1001    100.00     2013-11-02
1002    250.00     2014-01-23
1003    320.00     2014-02-02
1004    300.00     2014-03-04
1004     90.00     2014-03-05
1004     50.00     2014-04-21
1005    400.00     2014-04-21
Run Code Online (Sandbox Code Playgroud)

我希望得到一个列表,其中月份是唯一的,如下所示:

Months
2013-10-01
2013-11-01
2014-01-01
2014-02-01
2014-03-01
2014-04-01
Run Code Online (Sandbox Code Playgroud)

那可行吗?或者我是否需要进行其他类型的查询并在PHP中使用它?

mysql sql

1
推荐指数
1
解决办法
1511
查看次数

标签 统计

mysql ×3

date ×2

select ×1

sql ×1

time ×1