日期:2014-05-16 浏览次数:20644 次
select AVG(Price) from A WHERE
name = 1 and num = 2 and Y = 3 Date >= '2014-03-1' and Date <=GETDATE()
select AVG(Price) from A WHERE
name = 1 and num = 2 and Y = 3 Date >= '2014-02-1' and Date <=GETDATE()
select AVG(Price) from A WHERE
name = 1 and num = 2 and Y = 3 Date >= '2014-01-1' and Date <=GETDATE()
select AVG(Price) from A WHERE
name = 1 and num = 2 and Y = 3 Date >= '2013-12-1' and Date <=GETDATE()
SELECT AVG(Price)
FROM A
WHERE name = 1
AND num = 2
AND Y = 3
AND ( Date >= '2014-03-1'
AND Date <= GETDATE()
)
OR ( Date >= '2014-02-1'
AND Date <= GETDATE()
)
OR ( Date >= '2014-01-1'
AND Date <= GETDATE()
)
OR ( Date >= '2013-12-1'
AND Date <= GETDATE()
)
select * from A where
Date between Convert(varchar(7),(select Max(Date) from A),23)+'-01' and getdate()
and name = 1 and num = 2 and Y = 3
--用union all 连接
select AVG(Price) avg_price from A
WHERE name = 1 and num = 2 and Y = 3 Date >= '2014-03-1' and Date <=GETDATE()
union all
select AVG(Price) from A
WHERE name = 1 and num = 2 and Y = 3 Date >= '2014-02-1' and Date <=GETDATE()