الانتقال إلى المحتوى
View in the app

A better way to browse. Learn more.

مجموعة مستخدمي أوراكل العربية

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

اريد عمل كويري تطلع جدول فيه صاحب اعلى راتب في قسمه

Featured Replies

بتاريخ:

اريد عمل كويري تطلع جدول فيه صاحب اعلى راتب في قسمه


مثال


احمد 3000 المبيعات
خالد 4400 الموجودات


......
...


وهذي محاولاتي التي لم تنجح



select ename, sal, deptno from emp where exists (select deptno ,max(sal) from emp group by deptno) ;



select e.ename,subquery1.deptno
from emp e,
  (select deptno  , max(sal) 
  from emp group by deptno)  subquery1
where subquery1.deptno = e.deptno;


select e.ename,e.sal from emp e where exists ( select s.deptno,max(s.sal) from emp s where s.deptno=e.deptno group by deptno);

بتاريخ:
  • كاتب الموضوع

خلااااص عرفته

select ename,deptno, sal from emp where sal in (select max(sal) from emp group by deptno)

اللي ماكنت اعرفه انه ممكن نستخدم الAGG FN& GROUP BY بدون مانحط كولمن معين

بتاريخ:

حلك خطأ...
خود هل مثال حسب حلك:
مثلاً قسم 20 فيه أعلى راتب 2000 حلك بيجبلك كل الموظفين يلي راتبون 2000 سواء كانو بقسم 20 أو غيروا
هذا الحل الصحيح:
طريقة أولى باستخدام الثنائيات

select ename,deptno,sal from emp e where (sal,deptno) in (select max(sal),deptno
from emp group by deptno)
/


طريقة ثانية باستخدام Correlated

select ename,deptno,sal from emp e where sal in (select max(sal)
from emp where deptno=e.deptno group by deptno)
/

بتاريخ:
  • كاتب الموضوع

صدقت خيو .. ماكنت ملاحظ هذا الشي


مع اني اتذكر جربت فكرة الاول بس ماصار .. يمكن كان عندي خطأ في الكتابة

عموما
جزاك الله الف خير وكثر من أمثالك :rolleyes:

بتاريخ:

SELECT * FROM EMP OUTER
    WHERE SAL = (SELECT MAX(SAL) FROM EMP WHERE DEPTNO = OUTER.DEPTNO) 
    ORDER BY SAL DESC ;



AND THE RESULT WILL BE LIKE THAT

EMPNO ENAME   JOB             MGR   HIREDATE    SAL  COMM DEPTNO
--------  ---------- -------------- ------- --------- ----- ----- ------   ----------
7839   KING       PRESIDENT           17-NOV-81  5000            10
7788   SCOTT    ANALYST     7566  19-APR-87  3000            20
7902   FORD      ANALYST    7566   03-DEC-81  3000            20
7698   BLAKE     MANAGER   7839   01-MAY-81  2850           3

0

بتاريخ:
طريقة ثانية باستخدام Correlated
select ename,deptno,sal from emp e where sal in (select max(sal)
from emp where deptno=e.deptno group by deptno)
/



هو طبعاً ما في داعي لعملية Group by ...
بتاريخ:

select rownum, deptno, empcount
from
(
select deptno, count(empno) empcount
from emp
group by deptno
order by count(empno)
)
where rownum = 1

بتاريخ:

روعة The last one ماكنت اعرف هالطريقة وجزاك الله عنا كل خير

بتاريخ:

Thank you so much 'God'

:rolleyes:
You are so sweet so that I will give you another select statement

select empno ,deptno , ename , sal
 from (
	select empno ,deptno, ename, sal,
	dense_rank()
	over (partition by deptno
		 order by sal desc)drnk
	  from emp
	  where sal is not null
   ) where drnk = 1
 order by deptno, sal desc
/

:D[/b][/b]

تم تعديل بواسطة the last one

انضم إلى المناقشة

يمكنك المشاركة الآن والتسجيل لاحقاً. إذا كان لديك حساب, سجل دخولك الآن لتقوم بالمشاركة من خلال حسابك.

زائر
أضف رد على هذا الموضوع...

برجاء الإنتباه

بإستخدامك للموقع فأنت تتعهد بالموافقة على هذه البنود: سياسة الخصوصية

Account

Navigation

البحث

إعداد إشعارات المتصفح الفورية

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.