create or replace view monatl_forderung_heute as
    select
        m.id as mieter,
        w.id as wohnung,
        o.id as objekt,
        w.flaeche as flaeche,
        b.betrag as bkv_qm,
        (b.betrag * w.flaeche) as bkv,
        mz.betrag as miete_qm,
        (mz.betrag * w.flaeche) as miete
    from
        mieter m,
        objekt o,
        wohnung w,
        betriebskosten_vorauszahlung b,
        miete mz
    where
        o.id = w.objekt and
        w.id = m.wohnung and
        o.id = b.objekt and
        w.id = mz.wohnung and
        b.gueltig_ab <= now() and
        (b.gueltig_bis is null or b.gueltig_bis >= now()) and
        mz.gueltig_ab <= now() and
        (mz.gueltig_bis is null or mz.gueltig_bis >= now());

