hey guys, i am trying to get current income for th...
# sql
k
hey guys, i am trying to get current income for this month in my app: i have two tables where i have
project_time_entries
with columns
duration
in minutes, and table `project_members`where i have column `cost_rate`which is hourly rate of employee. so what i want is to join those two tables, calculate all durations for this month and get income. this is what i trie and it returns me duplicated rows
Copy code
create or replace function get_time_entries_income (
  start_date text, end_date text
) 
    returns table (
        duration integer,
        cost_rate integer
    ) 
    language plpgsql
as $$
begin
    return query 
        select pt.duration, p.cost_rate
        from project_time_entries pt
        inner join project_members p
        on pt.member_id = p.member_id
        where work_date between start_date and end_date;
end
$$;