Mysql 使用所有三合一查询?在子查询中? id date 2 2011-05-14 09:17:25 5 2011-05-16 09:17:25 6 2011-05-17 09:17:25 8 2011-05-20 09:17:25 15 20
使用所有三合一查询?在子查询中?Mysql 使用所有三合一查询?在子查询中? id date 2 2011-05-14 09:17:25 5 2011-05-16 09:17:25 6 2011-05-17 09:17:25 8 2011-05-20 09:17:25 15 20,mysql,sql,database,datetime,Mysql,Sql,Database,Datetime,使用所有三合一查询?在子查询中? id date 2 2011-05-14 09:17:25 5 2011-05-16 09:17:25 6 2011-05-17 09:17:25 8 2011-05-20 09:17:25 15 2011-05-22 09:17:25 select id from table where date >= "$sunday-date" + interval 7 DAY $date = date('Y-m-d H:i:s',time(
id date
2 2011-05-14 09:17:25
5 2011-05-16 09:17:25
6 2011-05-17 09:17:25
8 2011-05-20 09:17:25
15 2011-05-22 09:17:25
select id
from table
where date >= "$sunday-date" + interval 7 DAY
$date = date('Y-m-d H:i:s',time()-(7*86400)); // 7 days ago
$sql = "SELECT * FROM table WHERE date <='$date' ";
SELECT id FROM tbl
WHERE date >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY
AND date < curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY
SELECT id
FROM `Mytable`
where MyDate BETWEEN "2011-05-15" AND "2011-05-21"
select id from tbname
where date between date_sub(now(),INTERVAL 1 WEEK) and now();
SELECT id FROM tbl
WHERE
WEEK (date) = WEEK( current_date ) - 1 AND YEAR( date) = YEAR( current_date );
SELECT id FROM tbl
WHERE
WEEK (date) = WEEK( current_date ) - 2 AND YEAR( date) = YEAR( current_date );
SELECT id FROM tb1
WHERE
YEARWEEK (date) = YEARWEEK( current_date -interval 1 week )
DECLARE @StartDate DATETIME
DECLARE @EndDate DATETIME
SET @StartDate = Getdate() - 7 /* Seven Days Earlier */
SET @EndDate = Getdate() /* Now */
SELECT id
FROM mytable
WHERE date BETWEEN @StartDate AND @Enddate
SET @StartDate = Getdate() - 8 /* Eight Days Earlier */
SET @EndDate = Getdate() - 1 /* Yesterday */
Declare @Daytype varchar(15),
@StartDate datetime,
@EndDate datetime
set @Daytype = datename(dw, getdate())
if @Daytype= 'Monday'
begin
set @StartDate = getdate()-7
set @EndDate = getdate()-1
end
else if @Daytype = 'Tuesday'
begin
set @StartDate = getdate()-8
set @EndDate = getdate()-2
end
Else if @Daytype = 'Wednesday'
begin
set @StartDate = getdate()-9
set @EndDate = getdate()-3
end
Else if @Daytype = 'Thursday'
begin
set @StartDate = getdate()-10
set @EndDate = getdate()-4
end
Else if @Daytype = 'Friday'
begin
set @StartDate = getdate()-11
set @EndDate = getdate()-5
end
Else if @Daytype = 'Saturday'
begin
set @StartDate = getdate()-12
set @EndDate = getdate()-6
end
Else if @Daytype = 'Sunday'
begin
set @StartDate = getdate()-13
set @EndDate = getdate()-7
end
select @StartDate,@EndDate
SELECT id
FROM table
WHERE date >= current_date - 7
SELECT id FROM table1
WHERE YEARWEEK(date) = YEARWEEK(NOW() - INTERVAL 1 WEEK)
SELECT * FROM table WHERE Date BETWEEN (NOW() - INTERVAL 7 DAY) AND NOW()
WHERE yourDateColumn > DATEADD(DAY, -7, GETDATE()) ;
SELECT.....
WHERE CAST( yourDateColumn AS DATE ) > DATEADD( DAY, -7, CAST( GETDATE() AS DATE )
SELECT *
FROM inventory
WHERE YEARWEEK(`modify`, 1) = YEARWEEK(CURDATE(), 1)
SELECT id FROM tbl
WHERE
date >= curdate() - INTERVAL DAYOFWEEK(curdate())+5 DAY
AND date < curdate() - INTERVAL DAYOFWEEK(curdate())-2 DAY
where("actions.created_at >= DATE_SUB(CURDATE(), INTERVAL 1 WEEK)")
WHERE
WEEK(yourdate) = WEEK(NOW()) - 1
WHERE
WEEK(yourdate, 3) = WEEK(NOW(), 3) - 1
SELECT name, created_at
FROM employees
WHERE
YEARWEEK(`created_at`, 1) = YEARWEEK( CURDATE() - INTERVAL 1 WEEK, 1)
SELECT UserName, InsertTime
FROM tblaccounts
WHERE WEEK(InsertTime) = WEEK(NOW()) - 1;
SELECT UserName, InsertTime
FROM tblaccounts
WHERE MONTH(InsertTime) = MONTH(NOW()) - 1;
SELECT UserName, InsertTime
FROM tblaccounts
WHERE YEAR(InsertTime) = YEAR(NOW()) - 1;
SELECT date FROM table_name WHERE DATE(date) >= CURDATE() - INTERVAL 7 DAY;