【发布时间】:2017-11-02 21:44:43
【问题描述】:
我正在寻找记录,我遇到了一个场景,我必须在使用内部连接的选择查询之间包含额外的 where 子句。
select stp.sales_person as "Sales_Person",
max(case when stp.jan_month is null then 0 else stp.jan_month end) as "January",
select sum(so.amount_total) from sale_order so inner join res_users ru on ru.id=so.user_id
where date(so.confirmation_date) > '2017-01-01' and date(so.confirmation_date) < '2017-01-30',
max(case when stp.feb_month is null then 0 else stp.feb_month end) as "February",
max(case when stp.march_month is null then 0 else stp.march_month end) as "March",
max(case when stp.dec_month is null then 0 else stp.dec_month end) as "December"
from sales_target_record stp
inner join res_partner rp on rp.name=stp.sales_person inner join res_users ru on ru.partner_id = rp.id inner join crm_team ct on ru.sale_team_id = ct.id
where ct.name = 'Direct Sales' group by stp.sales_person
我必须像我尝试使用 sum 一样插入列,但不能作为连接查询工作
【问题讨论】:
-
MySQL SQL Server PostgreSQL。请标记您实际使用的那个。
-
您的
so.amount_total之后没有END用于您的Case声明 -
Select声明必须包含在()中,如果您希望它作为一个列。 -
但在这种情况下,使用此特定选择的内部连接会导致问题
标签: postgresql openerp