בעיה דחופה

yochi24

New member
בעיה דחופה

קצת קשה אבל אשמח לקבל תשובה במהירות , יש לי deadline עד הערב אם הנתונים מגיעים מעוותים נא להסתכל בקובץ המצורף או להעתיק את השאלה לnotepad מטרה: בכל חודש mechirot_shnati לעדכן את השדה בסה"כ מכירות מצטברים מתחילת השנה עד החודש הנוכחי בכל חודש לכל כלי התלויים ביצרן, דגם, שנה, חודש הרעיון: מכירות שנתי מכירות חודשי חודש שנה 2001 1 10 20 2001 2 30 50(=20+20) מכירות מצטבר שנתי חודש קודם + מכירות חודש נוכחי 2001 3 10 60(=50+10) וכך הלאה פתרון מוצע שלא פועל היישום update IGUD$ set mechirot_shnati=mechirot_chodesh+A1.mechirot_shnati from IGUD$ ,(select distinct basic_kod_kli,kod_tozar,degem,year,month, mechirot_shnati from IGUD$ --where year=2001 and basic_kod_kli=189 and degem=´A35´ and kod_tozar=875 ) A1 where IGUD$.basic_kod_kli=A1.basic_kod_kli and IGUD$.kod_tozar=A1.kod_tozar and IGUD$.degem=A1.degem and dateadd(month,-1,convert(datetime,A1.year+A1.month+´01´ ))= --חודש קודם (convert(datetime,IGUD$.year +IGUD$.month+´01´ ) ) --חודש נוכחי
 

yochi24

New member
פתרון(שושו-אם אתה רואה זאת )../images/Emo24.gif

העיקרון: (שושו-אם אתה רואה זאת - אתה גאון) update sales set מצטבר מתחילת שנה עד חודש נוכחי של מכירות= (select sum(מכירות חודש) from sales b where b.shana=a.shana and b.chodesh<=a.chodesh) from sales a update IGUD_sales set mechirot_ad_chodesh_kodem= (select sum(b.mechirot_chodesh) from IGUD_sales b where b.year=A.year and b.month<=A.month and b.shnat_yizur=A.shnat_yizur and b.basic_kod_kli=A.basic_kod_kli and b.kod_tozar=A.kod_tozar and b.degem=A.degem group by b.basic_kod_kli,b.kod_tozar,b.degem,b.year) from IGUD_sales A
 
למעלה