Lets say I have two tables as such:
People
Id Name FirstDate LastDate
-- -------- --------- --------
A1 Bob 1/1/2007 5/6/2007
A2 Joe 1/4/2008 9/1/2008
.. .. ... ...
PiesBaked
Name Date Value
-------- ---- -----
Bob 1/1/2007 7
Bob 1/2/2007 9
.. ... ...
Joe ... ...
How can I construct a view that subsets PiesBaked to First/Last Date for a Name
Result
Id Name Date Value
-- ---- ---- -----
A1 Bob 1/1/2007 7
A1 Bob 1/2/2007 9
.. .. ... ...
A1 Bob 5/6/2007 ...
.. ... ... ...
Try this:
SELECT a.Id, a.Name, b.Date, b.Value
FROM People a INNER JOIN PiesBaked b
ON a.Name = b.Name
AND b.Date BETWEEN a.FirstDate AND a.LastDate
select p.id, p.name, pb.Date, pb.value
from people p
inner join piesBaked pb
on pb.name = p.name
and pb.date between p.firstDate and p.lastDate
order by p.id, pb.Date
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.