الانتقال إلى المحتوى

أريد حلاً للسؤال


simpa2000f

Recommended Posts

السلام عليكم

سؤال في sql وهو :
Write a query that displays the employee’s last names with the first letter capitalized and all
other letters lowercase, and the length of the names, for all employees whose name starts with
J, A, or M. Give each column an appropriate label. Sort the results by the employees’ last
names.
:)

رابط هذا التعليق
شارك

السلام عليكم
سؤالين محيريني ياريت ألقى الجواب :
Display the last name, hire date, and day of the week on which the employee started. Label
the column DAY. Order the results by the day of the week starting with Monday.


السؤال الثاني :
Create a query that displays the employees’ last names and indicates the amounts of their
annual salaries with asterisks. Each asterisk signifies a thousand dollars. Sort the data in
descending order of salary. Label the column EMPLOYEES_AND_THEIR_SALARIES.

رابط هذا التعليق
شارك

محاوله في السؤال الاول اتمنى تقييمها من الخبراء

SELECT ENAME||TO_CHAR(HIREDATE,'FMDAY')||',' ||HIREDATE"employee started.Lable"
FROM EMP ORDER BY TO_CHAR(HIREDATE,'D')
/

رابط هذا التعليق
شارك

هذا الناتج اللي طلع عندي
أنا أريد الترتيب يبدأ من يوم الأثنين

الله يوفقك
[/sql]
employee started.Lable
-------------------------
WARDSUNDAY,22-FEB-81
SCOTTSUNDAY,19-APR-87
MARTINMONDAY,28-SEP-81
CLARKTUESDAY,09-JUN-81
KINGTUESDAY,17-NOV-81
TURNERTUESDAY,08-SEP-81
SMITHWEDNESDAY,17-DEC-80
JONESTHURSDAY,02-APR-81
JAMESTHURSDAY,03-DEC-81
FORDTHURSDAY,03-DEC-81
ALLENFRIDAY,20-FEB-81
BLAKEFRIDAY,01-MAY-81
ADAMSSATURDAY,23-MAY-87
MILLERSATURDAY,23-JAN-82

رابط هذا التعليق
شارك

السلام عليكم
اعتقد ان رد ابو عبدالله كان كافيا ،لكن يمكن ان تضيف بعض التعديلات

select last_name,hire_date,to_char(hire_date,'FMDAY') DAY
from employees order by to_char(hire_date,'D')


سوف يكون الناتج من hr schema وسوف يكون جزء من الناتج كالتالي :

LAST_NAME              HIRE_DATE DAY
------------------------- --------- ---------
Kaufling                  01-MAY-95 MONDAY
Mikkilineni            28-SEP-98 MONDAY
Errazuriz              10-MAR-97 MONDAY
Bernstein              24-MAR-97 MONDAY
Patel                  06-APR-98 MONDAY
Olsen                  30-MAR-98 MONDAY
Smith                  10-MAR-97 MONDAY
Marvins                24-JAN-00 MONDAY
Grant                  24-MAY-99 MONDAY
OConnell                  21-JUN-99 MONDAY
Everett                03-MAR-97 MONDAY
Sullivan                  21-JUN-99 MONDAY
Fleaur                    23-FEB-98 MONDAY
Bloom                  23-MAR-98 MONDAY
Doran                  15-DEC-97 MONDAY
Sully                  04-MAR-96 MONDAY
Ernst                  21-MAY-91 TUESDAY
Faviet                    16-AUG-94 TUESDAY


في حال كنت راغبا بان يكون الناتج من scott schema يمكنك تغيير بعض الاسماء لكن الاسم الاخير غير موجود في سكوت سكيما
رابط هذا التعليق
شارك

للسؤال الثاني:

من hr schema كالتالي:

select rpad(last_name,15,' ') || lpad(' ' ,(salary/1000),'*') EMPLOYEES_AND_THEIR_SALARIES
from employees order by salary desc



و من scott schema كالتالي:

select rpad(ename,15,' ') || lpad(' ' ,(sal/1000),'*') EMPLOYEES_AND_THEIR_SALARIES
from emp order by sal desc



سيكون جزء من الناتج كتالي:


EMPLOYEES_AND_THEIR_SALARIES
---------------------------------------------
King           ***********************
Kochhar        ****************
De Haan        ****************
Russell        *************
Partners       ************
Hartstein      ************
Greenberg      ***********
Errazuriz      ***********
Higgins        ***********
Ozer           **********
Raphaely       **********
Cambrault      **********
Abel           **********
Zlotkey        *********
Vishney        *********

رابط هذا التعليق
شارك

السلام عليكم
ممكن ألأقى جواب لسؤالين :

[/sql]Create a query that will display the total number of employees and, of that total, the number of
employees hired in 1995, 1996, 1997, and 1998. Create appropriate column headings.

2-Create a matrix query to display the job, the salary for that job based on department number,
and the total salary for that job, for departments 20, 50, 80, and 90, giving each column an
appropriate heading.
رابط هذا التعليق
شارك

السلام عليكم
للسؤال الاول

select count(ename) from emp



select  count(ename) from emp where to_char(hiredate,'YYYY') in (1995,1996,1997,1998)



الاول ينتج منه العدد الكلي للموظفين ،،الثاني ينتج منه عدد الموظفين العاملين في التواريخ المعطاه فقط..
لكني لا اعرف كيف اظهر الناتجان في ان واحد ،،لو يساعدنا احد من خبراء المنتدى

رابط هذا التعليق
شارك

نعم يوجد إجابة للسؤال الثاني وهي:

select job "JOB" ,
sum(decode(deptno,10,sal)) "department 10",
sum(decode(deptno,20,sal)) "department 20",
sum(decode(deptno,30,sal)) "department 30",
sum(sal) "Total"
from emp
group by job;


مع تميانتي بالتوفيق

رابط هذا التعليق
شارك

  • بعد 2 سنة...

الاخت همس
اشكرك على حل المثال السابق والشرح
واذا تكرمت ممكن حل مثال اخر على نفس المعنى تقريبا
وعلى نفس قاعدة التدريب للمستخدم scott
وهومع ظهور الراتب 1000 تظهر علامة asterisk امامه في حقل جديد مرة واحدة
ومع ظهور الراتب 2210 تظهر علامة asterisk امامه في حقل جديد مرتان
ومع ظهور الراتب 3450 تظهر علامة asterisk امامه في حقل جديد 3 مرات
وكل asterisk معناها طبعا الف وهكذا
وهذا طبعا في حقل جديد بعنوان new_sal
واشكرك كثيرا جدا اذا ساعدتني
ويارب يكون حل سريع

اختك نهاد

رابط هذا التعليق
شارك

بسم الله وان كن بعد سنتين ولكن من أجل فائدة الجميع
جواب السؤال عن الترتيب بدء من Monday
select ename , hiredate , to_char(hiredate,'day d') day
from emp
order by decode(to_char(hiredate,'d'),2,1,3,2,4,3,5,4,6,5,7,6,1,7,0)
/
--------------------------------------------
select ename , hiredate , to_char(hiredate,'day d') day
from emp
order by
decode(to_char(hiredate,'dy')
,'MON',1,'TUE',2,'WED',3,'THU',4,'FRI',5,'SAT',6,'SUN',7,0)
/
-------------------------------------------
أما بالنسبة لجمع الموظفين المعيينين حسب تاريخ التوظيف فهو كالآتي:

SELECT count(employee_id)
, sum(decode(to_char(hire_date,'yyyy'),'1995',1,0)) "hired 1995"
, sum(decode(to_char(hire_date,'yyyy'),'1996',1,0)) "hired 1996"
, sum(decode(to_char(hire_date,'yyyy'),'1997',1,0)) "hired 1997"
, sum(decode(to_char(hire_date,'yyyy'),'1998',1,0)) "hired 1998"
from employees
/

رابط هذا التعليق
شارك

الاخت همس
اشكرك على حل المثال السابق والشرح
واذا تكرمت ممكن حل مثال اخر على نفس المعنى تقريبا
وعلى نفس قاعدة التدريب للمستخدم scott
وهومع ظهور الراتب 1000 تظهر علامة asterisk امامه في حقل جديد مرة واحدة
ومع ظهور الراتب 2210 تظهر علامة asterisk امامه في حقل جديد مرتان
ومع ظهور الراتب 3450 تظهر علامة asterisk امامه في حقل جديد 3 مرات
وكل asterisk معناها طبعا الف وهكذا
وهذا طبعا في حقل جديد بعنوان new_sal
واشكرك كثيرا جدا اذا ساعدتني
ويارب يكون حل سريع

اختك نهاد



SELECT SAL,LPAD(' ',TRUNC(SAL/1000),'*')  new_sal FROM EMP

رابط هذا التعليق
شارك

  • بعد 10 شهور...

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

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

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

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   تمت استعادة المحتوى السابق الخاص بك.   مسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

جاري التحميل
×
×
  • أضف...

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

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