sql查询数据 max的日期最大的那条数据小于某个值0
abaidu612015.01.03浏览74次分享举报
select b.TAB_ID, b.TAB_UNIT_ID, a.unit_id, a.unit_name, b.TAB_STATE, c.name, d.temp_type, a.task_start_time, a.task_end_time, b.TAB_UNIT_VALUE, e.unit_value, b.TAB_DATE_TIME, convert(varchar(10),e.data_time, 20) data_time from lz_prod... select
b.TAB_ID,
b.TAB_UNIT_ID,
a.unit_id,
a.unit_name,
b.TAB_STATE,
c.name,
d.temp_type,
a.task_start_time,
a.task_end_time,
b.TAB_UNIT_VALUE,
e.unit_value,
b.TAB_DATE_TIME,
convert(varchar(10),e.data_time, 20) data_time
from lz_product_unit a
left join LZ_DATETASK_TABLE b on a.unit_id = b.TAB_UNIT_ID
left join lz_admin c on a.admin_id = c.admin_id
left join lz_product_template d on a.temp_id = d.temp_id
left join lz_product_unit_value e on a.unit_id = e.unit_id and
e.data_time =
(
select max(f.data_time) from lz_product_unit_value f where f.unit_id = e.unit_id
)
where b.TAB_ID is NULL or
(select max(g.TAB_DATE_TIME) from LZ_DATETASK_TABLE g where g.TAB_UNIT_ID = e.unit_id ) < convert(varchar(10),e.data_time, 20)
为什么是这面这种情况
怎么实现查询结果是这种情况,只显示max(g.TAB_DATE_TIME)这个
展开