بتاريخ: 20 سبتمبر 201213 سنة comment_227577 السلام عليكماخوانى الاعزاء .وجهتنى مشكله فى انشاء جمله SQl تسمح بعرض الموظفين المتفرعين من مدير معين.. و ذلك سهل ف حاله مستوى واحد فقط .. و لكن المشكله واجهتنى مع مدير الشركه او مدير تحته اقسام و فى كل قسم مدير و متفرع منه موظفين . قد تصل الشجرة الى اكثر من 4 مستوياتو لذلك لطريقه المباشرة فى الكود سوف تعرض المديرين فقط المتفرعين من رئيس الشركة و لكن لن تعرض من هم متفرع من المديرين .السؤال :ما هى جمله ال sql التى سوف تتيح لي كل الموظفين المتفرعين من موظف معين .. بافتراض ان مدير القسم هو موظف و بافتراض ان رئيس الشركة موظف ؟ ارجوا اكون قد وقفت فى توصيل الفكرة وشكرا لكم تقديم بلاغ
بتاريخ: 4 أكتوبر 201213 سنة comment_227802 السلام عليكم ورحمة الله وبركاتهأخي الكريمقم بربط الجدول مع نفسة أكثر من مرة حسب عدد المستويات التى تحتاج لها كما في الكود التالي Create table act ( seq integer , /*التسلسل*/ ac_num integer , /*رقم الحساب_إبن*/ ac_nam varchar2(75) , /*اسم الحساب*/ levl_c integer , /*مستوي الحساب_أب*/ ac_dat date default sysdate , /*تاريخ فتح الحساب*/ de_cr number(1) default 0 , /* تصنيف الحساب مدين 1 ، دائن 2 ، بلا 0*/ end1 number(1) default 0 , /*إغلاق الحساب الميزانية 1 ، الأرباح والخسائرالشاملة 2 ، تكلفة الإنتاج 3*/ icn varchar2(25) not null , /*اسم الأيقونة*/ constraint num_pk primary key ( ac_num) , constraint nam_uk unique (ac_nam) , constraint levl_c_fk foreign key ( levl_c ) references act(ac_num) ) ; create table tr_bal ( t_id integer , /*التسلسل*/ t_year integer , /*السنة المالية*/ t_num integer , /*رقم الحساب*/ t_op_vd number(12,3) default 0 , /*الرصيد الافتتاحي مدين*/ t_op_vc number(12,3) default 0 , /*الرصيد الافتتاحي دائن*/ t_t_vd number(12,3) default 0 , /*مجموع الحركات المدينة*/ t_t_vc number(12,3) default 0 , /*مجموع الحركات الدائنة*/ constraint tr_bal_pk primary key ( t_year , t_num ) , constraint tr_bal_fk foreign key ( t_num ) references act(ac_num) ) ; نشاء view مرتبط بميزان المراجعة : يتم من خلالها عرض ميزان المراجعة بشكل تجميعي للحسابات الرئيسية_ المستوي الأول create or replace view v_t_tr_bal_3 (yer, de_cr, num, nam, op_vd, op_vc, t_vd, t_vc, vd, vc) as select t_year , act4.de_cr , act4.ac_num , act4.ac_nam , nvl(sum(t_op_vd),0) , nvl(sum(t_op_vc),0) , nvl(sum(t_t_vd),0) , nvl(sum(t_t_vc),0) , (nvl(sum(t_op_vd),0) - nvl(sum(t_op_vc),0) + nvl(sum(t_t_vd),0) - nvl(sum(t_t_vc),0)) , 0 from act , tr_bal , act act2 , act act3 , act act4 where act.ac_num=t_num and act.levl_c=act2.ac_num and act2.levl_c=act3.ac_num and act3.levl_c=act4.ac_num and act4.de_cr =1 group by t_year , act4.de_cr , act4.ac_num , act4.ac_nam union all select t_year , act4.de_cr , act4.ac_num , act4.ac_nam , nvl(sum(t_op_vd),0) , nvl(sum(t_op_vc),0) , nvl(sum(t_t_vd),0) , nvl(sum(t_t_vc),0) , 0 , -(nvl(sum(t_op_vd),0) - nvl(sum(t_op_vc),0) + nvl(sum(t_t_vd),0) - nvl(sum(t_t_vc),0)) from act , tr_bal , act act2 , act act3 , act act4 where act.ac_num=t_num and act.levl_c=act2.ac_num and act2.levl_c=act3.ac_num and act3.levl_c=act4.ac_num and act4.de_cr =2 group by t_year , act4.de_cr , act4.ac_num , act4.ac_nam ; جزاك الله كل خير تقديم بلاغ
بتاريخ: 21 أكتوبر 201213 سنة comment_228237 كيف يتم عرض المستويات كاعمدة بدلا من صفوف . يعني الحساب المستوى الاول .. الحساب المستوى الثاني .. وهكذا تقديم بلاغ
بتاريخ: 21 أكتوبر 201213 سنة comment_228261 السلام عليكم ورحمة الله وبركاتهأخي الكريمقم بتجربة استخدام decodeحيث الكود التالي من خلالة يتم إظهار رصيد كل الحسابات بشكل شهري وكل شهر يكون في عامود مستقل select num , nam, sum(vd-vc) , sum(decode(to_char(dat,'mm'),'01', (vd-vc),0)) "mon 1" , sum(decode(to_char(dat,'mm'),'02', (vd-vc),0)) "mon 2" , sum(decode(to_char(dat,'mm'),'03', (vd-vc),0)) "mon 3" , sum(decode(to_char(dat,'mm'),'04', (vd-vc),0)) "mon 4" , sum(decode(to_char(dat,'mm'),'05', (vd-vc),0)) "mon 5" , sum(decode(to_char(dat,'mm'),'06', (vd-vc),0)) "mon 6" , sum(decode(to_char(dat,'mm'),'07', (vd-vc),0)) "mon 7" , sum(decode(to_char(dat,'mm'),'08', (vd-vc),0)) "mon 8" , sum(decode(to_char(dat,'mm'),'09', (vd-vc),0)) "mon 9" , sum(decode(to_char(dat,'mm'),'10', (vd-vc),0)) "mon 10" , sum(decode(to_char(dat,'mm'),'11', (vd-vc),0)) "mon 11" , sum(decode(to_char(dat,'mm'),'12', (vd-vc),0)) "mon 12" from v_ent_act where d_c_num = _ACT and to_number(to_char(dat,'YYYY')) = _YEAR group by num , nam order by num ; أو يمكن إستخدام جملة select داخل الكود أكثر من مرة كما يلي create or replace view income ( yer , sal , pur , sal_rt , pur_rt , incom2 , adm_exp , sell_exp , othr_exp , tax_exp , deprec , sal2 , sal_rt2 , sal3 , sal_rt3 , open_invt , salcost2 , salcost3 , end_invt , indstcost ) as select (to_number(to_char(sysdate,'YYYY'))) , ( select nvl(sum(vc),0) from v_tr_bal_2 where yer = (to_number(to_char(sysdate,'YYYY'))) and num between 4700001 and 4709999 ) , ( select nvl(sum(vd),0) from v_tr_bal_2 where yer = (to_number(to_char(sysdate,'YYYY'))) and num between 4710001 and 4719999 ) , ( select nvl(sum(vd),0) from v_tr_bal_2 where yer = (to_number(to_char(sysdate,'YYYY'))) and num between 4720001 and 4729999 ) , ( select nvl(sum(vc),0) from v_tr_bal_2 where yer = (to_number(to_char(sysdate,'YYYY'))) and num between 4730001 and 4739999 ) , ( select nvl(sum(vc),0) from v_tr_bal_2 where yer = (to_number(to_char(sysdate,'YYYY'))) and num between 4740001 and 4749999 ) , ( select nvl(sum(vd),0) from v_tr_bal_2 where yer = (to_number(to_char(sysdate,'YYYY'))) and num between 4800001 and 4809999 ) , ( select nvl(sum(vd),0) from v_tr_bal_2 where yer = (to_number(to_char(sysdate,'YYYY'))) and num between 4810001 and 4819999 ) , ( select nvl(sum(vd),0) from v_tr_bal_2 where yer = (to_number(to_char(sysdate,'YYYY'))) and num between 4820001 and 4829999 ) , ( select nvl(sum(vd),0) from v_tr_bal_2 where yer = (to_number(to_char(sysdate,'YYYY'))) and num between 4840000 and 4849999 ) , ( select nvl(sum(vd),0) from v_tr_bal_2 where yer = (to_number(to_char(sysdate,'YYYY'))) and num between 5100001 and 5169999 ) , ( select nvl(sum(vc),0) from v_tr_bal_2 where yer = (to_number(to_char(sysdate,'YYYY'))) and num between 4900001 and 4900002 ) , ( select nvl(sum(vd),0) from v_tr_bal_2 where yer = (to_number(to_char(sysdate,'YYYY'))) and num between 4900005 and 4900006 ) , ( select nvl(sum(vc),0) from v_tr_bal_2 where yer = (to_number(to_char(sysdate,'YYYY'))) and num between 4950001 and 4950002 ) , ( select nvl(sum(vd),0) from v_tr_bal_2 where yer = (to_number(to_char(sysdate,'YYYY'))) and num between 4950005 and 4950006 ) , ( select nvl(sum(vd),0) from v_tr_bal_2 where yer = (to_number(to_char(sysdate,'YYYY'))) and num = 7000001 ) , ( select nvl(sum(t_cost),0) from v_invtsal4_cost ) , ( select nvl(sum(t_cost),0) from v_invtsal6_cost ) , ( select nvl(sum(t_cost),0) from v_invt_2 ) , ( select nvl(sum(indstcost),0) from v_cost_inds12 ) from dual ; جزاك الله كل خير تقديم بلاغ
انضم إلى المناقشة
يمكنك المشاركة الآن والتسجيل لاحقاً. إذا كان لديك حساب, سجل دخولك الآن لتقوم بالمشاركة من خلال حسابك.