SELECT b.datetime,a.usr,a.area,a.code,b.elect,b.water ,max(b.elect) as mae , min(b.water) as miw FROM D_SCALE a JOIN D_WellData b ON b.datetime BETWEEN a.stime AND a.etime where a.area = b.area and a.code = b.code and a.usr = b. usr 为什么不能求elect字段的最大值和water字段的最小值,为什么呢?怎么修改呢?
SELECT b.datetime,a.usr,a.area,a.code,b.elect,b.water ,max(b.elect) as mae , min(b.water) as miw FROM D_SCALE a JOIN D_WellData b ON b.datetime BETWEEN a.stime AND a.etime where a.area = b.area and a.code = b.code and a.usr = b. usr
group by b.datetime,a.usr,a.area,a.code,b.elect,b.water
b.[datetime]
,a.usr
,a.area
,a.code
,b.elect
,b.water
,max(b.elect) as mae
, min(b.water) as miw
FROM D_SCALE a
JOIN D_WellData b
ON a.area = b.area and a.code = b.code and a.usr = b. usr and (b.[datetime] BETWEEN a.stime AND a.etime )a
group by
b.[datetime]
,a.usr
,a.area
,a.code
,b.elect
,b.water
如group by b.area=XX XX给个值,
如group by b.area=XX XX给个值,
如group by b.area=XX XX给个值,
group by返回的是按后面字段返回每个聚合的最大或最小值的