الانتقال إلى المحتوى
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

بتاريخ:

لكى نحضر جميع بيانات الموظف الذى يمتلك خامس أعلى مرتب من جدول ال Emp نقوم بتنفيذ الكود التالى :-

SELECT empno,ename,sal, rn FROM
(SELECT a.*, dense_rank() OVER(ORDER BY sal DESC) rn FROM emp a )
where rn=5;



أنا أريد تفسير لهذا الكود لأن به دالة جديدة و هى ال

(dense_rank() OVER(ORDER BY sal DESC

و هى دالة انا لم أتعرض لها من قبل ....... فأرجو الأفادة و شكراً

بتاريخ:

اخي الفاضل الدالة rank والدالة dense_rank هما من الدوالالتي تستعمل تحليليا analytic بهدف الترتيب

هذا المقال سيجيب عن كل تساؤلاتك

RANK, DENSE_RANK, FIRST and LAST Analytic Functions


The following examples use the EMP table from the SCOTT sample schema, which is created as follows.

 CONN sys/password AS SYSDBA

-- Create SCOTT schema if you don't currently have it.
@$ORACLE_HOME/rdbms/admin/utlsampl.sql
ALTER USER scott IDENTIFIED BY tiger ACCOUNT UNLOCK;



Let's assume we want to assign a sequential order, or rank, to people within a department based on salary, we might use the RANK function like:

  SELECT deptno,
	   ename,
	   sal,
	   RANK() OVER (PARTITION BY deptno ORDER BY sal) "rank"
FROM   emp
WHERE  deptno = 30;

	DEPTNO ENAME			 SAL	   rank
---------- ---------- ---------- ----------
		30 JAMES			 950		  1
		30 WARD			 1250		  2
		30 MARTIN		   1250		  2
		30 TURNER		   1500		  4
		30 ALLEN			1600		  5
		30 BLAKE			2850		  6



What we see here is where two people have the same salary they are assigned the same rank. When multiple rows share the same rank the next rank in the sequence is not consecutive.

The DENSE_RANK function works acts like the RANK function except that it assigns consecutive ranks:

 SELECT deptno,
	   ename,
	   sal,
	   DENSE_RANK() OVER (PARTITION BY deptno ORDER BY sal) "rank"
FROM   emp
WHERE  deptno = 30;

	DEPTNO ENAME			 SAL	   rank
---------- ---------- ---------- ----------
		30 JAMES			 950		  1
		30 WARD			 1250		  2
		30 MARTIN		   1250		  2
		30 TURNER		   1500		  3
		30 ALLEN			1600		  4
		30 BLAKE			2850		  5



The FIRST and LAST functions can be used to return the first or last value from an ordered sequence. Say we want to display the salary of each employee, along with the lowest and highest within their department we may use something like:

  SELECT deptno,
	   ename,
	   sal,
	   MIN(sal) KEEP (DENSE_RANK FIRST ORDER BY sal) OVER (PARTITION BY deptno) "Lowest",
	   MAX(sal) KEEP (DENSE_RANK LAST ORDER BY sal) OVER (PARTITION BY deptno) "Highest"
FROM   emp
ORDER BY deptno, sal;

	DEPTNO ENAME			 SAL	 Lowest	Highest
---------- ---------- ---------- ---------- ----------
		10 MILLER		   1300	   1300	   5000
		10 CLARK			2450	   1300	   5000
		10 KING			 5000	   1300	   5000
		20 SMITH			 800		800	   3000
		20 ADAMS			1100		800	   3000
		20 JONES			2975		800	   3000
		20 SCOTT			3000		800	   3000
		20 FORD			 3000		800	   3000
		30 JAMES			 950		950	   2850
		30 WARD			 1250		950	   2850
		30 MARTIN		   1250		950	   2850

	DEPTNO ENAME			 SAL	 Lowest	Highest
---------- ---------- ---------- ---------- ----------
		30 TURNER		   1500		950	   2850
		30 ALLEN			1600		950	   2850
		30 BLAKE			2850		950	   2850



بالتوفيق
بتاريخ:

اخواني انا تعرض لي هذا السؤال من قبل ولم اعارف ان في دالة بهذا الاسم بس برضو سمعت ان ممكن الحصول علي نفس النتيجة بدون الدالية بسب كويري في فروم كلاوس لو حد يعرف الطريقة التانية يعرضها للاستفادة

  • بعد 2 أسابيع...
بتاريخ:

أخوكم بهاء هذا هو الكود التالى :-

select empno,ename,sal,rownum
from (select empno,ename,sal from emp order by sal desc)
where rownum=5;



يارب اكون أفتك

[email protected]

بتاريخ:

الاخ / هانى
لو انت عاوز تفسير للداله اعتقد الاخوه قاموا بالللازم
اما لو كان يهمك النتيجه فاعتقد دى ممكن نعملها ببساطه باستخدام ال cursor

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

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

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

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

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

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.