asp.net - SQL update attribute -
i have table of milestones in primary key id_milestone , table tasks foreign key id_milestone. each task attribute completion in percentage. milestone have attribute of completion in percentage. need update completion of milestone @ 100 percent until have completed all tasks set 100 percent. have dropdownlist interval 10 percent , users update progress. sorry english.
create table milestone ( id_milestone integer not null , nazev_milniku varchar2 (30) , ) ; create table milestone_complete ( id_milestone integer not null , completed integer ) ; create table tasks ( id_tasks integer not null , id_milestone integer not null , name_task varchar2 (30) , ) ; create table tasks_complete ( id_task integer not null , completed integer ) ;
this calculate percentage of milestones using percentages of tasks.
update [milestones] set [percentage] = (select avg(pecentage) [tasks] [tasks].[id_milestone] = [milestones].[id])
if want set e.g. status flag [completed] can this:
update [milestones] set [completed] = (case when (select avg(pecentage) [tasks] [tasks].[id_milestone] = [milestones].[id]) = 100 1 else 0 end)
this guess want didn't comppletely show tables, structure, etc. hope helps.
edit
your table milestone
need column percentage
or want write result in other table milestone_complete? don't understand why have additional tables. guess have column percentage
in milestone
table. in case sql this:
update [milestone] set [percentage] = (select avg(pecentage) [tasks] [tasks].[id_milestone] = [milestone].[id_milestone])
if want write result in completed' column in the
milestone_complete` table, this:
update [milestone_complete] set [percentage] = (select avg(pecentage) [tasks] [tasks].[id_milestone] = [milestone].[id_milestone]) [milestone_complete] join [milestone] on [milestone].[id_milestone] = [milestone_complete].[id_milestone]
or want insert result milestone_complete
if tasks of milestone 100%? not know if have record in compelted table or need add on in case. assume have 1 , want set completed e.g. 1 (0 = not completed).
update [milestone_complete] set [completed] = 1 [milestone_complete] join [milestone] on [milestone].[id_milestone] = [milestone_complete].[id_milestone] (select avg(percentage) [tasks] [tasks].[id_milestone] = [milestone].[id_milestone])=100
i didn't test of it, not sure if works, not 100% approach need modify own needs. hope helps. next time ask question concentrate on clear, complete , understandable question, make easier.
Comments
Post a Comment