连接列来自不同的表,并获取已连接列的总数

时间:2013-12-16 14:58:13

标签: sql postgresql-9.1

我编辑了这个问题,这是有效的解决方案,

SELECT yesterday.yesterday, today.today, report.id, report.balance, 
    report.debit, report.credit, cumulative.cumulative, report.name
   FROM ( SELECT y.balance AS yesterday
           FROM report_account_receivable_yesterday) yesterday, 
    ( SELECT t.balance AS today
           FROM report_account_receivable_today) today, 
    ( SELECT sum(y.balance + t.balance) AS cumulative
           FROM report_account_receivable_yesterday y, 
            report_account_receivable_today t) cumulative, 
    ( SELECT min(l.id) AS id, 
            to_char(l.date::timestamp with time zone, 'YYYY:IW'::text) AS name, 
            sum(l.debit - l.credit) AS balance, sum(l.debit) AS debit, 
            sum(l.credit) AS credit, a.type, DATE 'now()' - interval '1 day' AS tarehe
           FROM account_move_line l
      LEFT JOIN account_account a ON l.account_id = a.id
     WHERE l.state::text <> 'draft'::text AND l.date = DATE 'now()' - interval '1 day'
     GROUP BY to_char(l.date:

:带时区的时间戳,'YYYY:IW':: text),a.type)报告   ORDER BY report.id DESC;

问题在于使用DATE 'now()' - interval '1 day'获取前一天的数据,因为它会在我的视图中为查询提供此输出

sum(l.credit) AS credit, a.type, '2013-12-16'::date AS tarehe
   FROM account_move_line l
   LEFT JOIN account_account a ON l.account_id = a.id
  WHERE l.state::text <> 'draft'::text AND l.date = '2013-12-16'::date

0 个答案:

没有答案