Wednesday 15 January 2014

sql - Select and join error must appear in the GROUP BY clause or be used in an aggregate function -



sql - Select and join error must appear in the GROUP BY clause or be used in an aggregate function -

i'm trying this:

select *, case when sum(fld_allocated_time) / 24 < fld_allocated_days 'ok' else 'nok' end alocated ( select tbl_project.fld_id, tbl_project.fld_allocated_days, tbl_project_timesheet.fld_allocated_time "sd_prj".tbl_project inner bring together "sd_prj".tbl_project_timesheet on tbl_project.fld_id=tbl_project_timesheet.fld_id ) alias

and error:

error: column "total.fld_id" must appear in grouping clause or used in aggregate function sql state: 42803 character: 8

tbl = table fld = column sd_prj = schema name

if want calculate single sum rows of query , compare fld_allocated_days in each row can seek this:

with alias ( select * ( select tbl_project.fld_id, tbl_project.fld_allocated_days, tbl_project_timesheet.fld_allocated_time "sd_prj".tbl_project inner bring together "sd_prj".tbl_project_timesheet on tbl_project.fld_id=tbl_project_timesheet.fld_id ) select a.*, case when b.sm < fld_allocated_days 'ok' else 'nok' end alocated alias cross bring together (select sum(fld_allocated_time) / 24 sm alias) b;

however, suppose need this:

select tbl_project.fld_id, case when sum(tbl_project_timesheet.fld_allocated_time) / 24 < fld_allocated_days 'ok' else 'nok' end alocated "sd_prj".tbl_project inner bring together "sd_prj".tbl_project_timesheet on tbl_project.fld_id=tbl_project_timesheet.fld_id grouping tbl_project.fld_id, tbl_project.fld_allocated_days;

sql postgresql postgresql-9.1

No comments:

Post a Comment