I am looking at creating a view from several tables which requires 5 columns. To create each column I need to perform various calculations and exceptions using the WHERE clause. for example
CREATE VIEW test
AS SELECT date1 as 'YEAR'
FROM booking
WHERE bookingDate BETWEEN '2010-01-01' and '2014-12-31'
this column works perfectly, but now i want to add a column next to it in the same view with a different WHERE clause. How can I add several SELECT statements where i can specify where boundaries for each column individually and also use different tables to do so?
Sample data:
Table 1
-------------------
BookingID | date
1001 | 2010-01-23
1002 | 2010-02-23
------------------------
Table 2
-----------------------
ProfitID | BookingID| Profit
44 | 1001 | £250
45 | 1002 | £200
----------------------------
Create VIEW
--------------------------
YEAR | Profit
2010 | £450