我有以下表格,我想进行可以给出结果5的查询(如下面的粗体所示)。
我试图查询,但是你不能帮忙吗?
SELECT utl_reader_route.reader_route_code,
utl_reader_route_date.read_date
FROM utl_reader_route_date
JOIN utl_reader_route
ON utl_reader_route.reader_route_id =
utl_reader_route_date.reader_route_id
JOIN utl_meter_reader
ON utl_reader_route.meter_reader_id = utl_meter_reader.meter_reader_id
WHERE utl_meter_reader.meter_reader_code = 'ADR MRS'
AND utl_reader_route_date.read_date BETWEEN '2014-05-01' AND '2014-05-31'
ORDER BY read_date
utl_meter_reader
meter_reader_id ......... meter_reader_code
1 ......... ADR MRS
2 ......... AGC
utl_reader_route
reader_route_id .......... meter_reader_id
1 ......... 1
2 ......... 2
utl_reader_route_date
reader_route_date_id ......... reader_route_id ......... read_date
1 ......... 1 ......... 20/04/2014
1 ......... 2 ......... 20/20/2014
1 ......... 3 ......... 20/06/2014
2 ......... 4 ......... 20/04/2014
2 ......... 5 .........
2 ......... 6 ......... 20/06/2014
3 ......... 7 ......... 20/04/2014
3 ......... 8 ......... 20/20/2014
3 ......... 9 ......... 20/06/2014
答案 0 :(得分:0)
假设您需要没有日期的记录。您可以输入Or子句并检查
之类的空日期select utl_reader_route.reader_route_code,utl_reader_route_date.read_date from
utl_reader_route_date join utl_reader_route on
utl_reader_route.reader_route_id=utl_reader_route_date.reader_route_id Join
utl_meter_reader on utl_reader_route.meter_reader_id=utl_meter_reader.meter_reader_id where
utl_meter_reader.meter_reader_code='ADR MRS' and utl_reader_route_date.read_date between '2014-05-01' and '2014-05-31' Or utl_reader_route_date.read_date is Null order by read_date