תשובות למבחן לדוגמא
- class928417
- Sep 5, 2014
- 2 min read
היי,
מצ"ב תשובות למבחן לדוגמא (מעודכן לאחר העדכון מרן לגבי שאלה 4).
במידה ויש טעות או שיש תשובות אחרות נא לשלוח אלי את התשובות למייל או פייסבוק ואני אעדכן באתר . המייל : class928417.wix@Gmail.com
התשובות מצורפות בהודעה זו אך גם בקובץ SQL שבו יש גם נתוני דמה להרצה/בדיקה.
*** בחלק מהפתרונות השתמשתי בפקודת DATEADD, ניתן לפתור גם עם DATEDIFF רק עם SYNTEX קצת אחר בפקודות ה-WHERE.
מצ"ב לינק לקובץ - קובץ תשובות
להלן התשובות :
-- Q1
Select
year(Transaction_Datetime) as TranYear
, max(Transaction_amt) as MaxAMT
From ATM_Trans
Where customer_ID=188
and Transaction_type=2
and year(transaction_datetime) in (2011,2012,2013)
Group by year(Transaction_datetime)
-- Q2
-- דרך א לפתרון
select
atm_id
from atm_machines
where atm_type = (select top(1) AM.Atm_type
from Atm_machines AM
inner join atm_trans AT on AM.atm_id=AT.atm_id
where AT.error_message like ('%hardware%')
group by AM.Atm_type
order by count(*) desc)
-- דרך ב לפתרון
select atm_id
from atm_machines AM
inner join (select AM1.atm_type
, count(*) as total
,row_number() over (order by count(am1.atm_id) desc ) as RankT
from atm_machines AM1
inner join atm_trans AT on at.atm_id=am1.ATm_id
where AT.error_message like ('%hardware%')
group by AM1.atm_type) as AM2
on am.atm_type=am2.atm_type
where am2.RankT=1
-- Q3
select
*
from ATM_trans
where transaction_datetime between dateadd(yy,-1,getdate()) and getdate()
and transaction_type<>6
and error_message is null
-- Q4
-- תשובה תוקנה
-- כאשר הבדיקה מול הממוצע החודשי של 2013
Select AT.customer_id--,Sum(AT.Transaction_amt)
from Atm_Trans AT
Where year(AT.transaction_datetime)=2014
and month(AT.transaction_datetime)=1
Group By AT.customer_id
Having Sum(AT.Transaction_amt) > (select sum(at2.Transaction_amt)/12
from Atm_Trans AT2
where year(AT2.transaction_datetime)=2013
and At.customer_id=AT2.customer_id)
-- Q5
select
*, case
when transaction_type in (1,3,4,5) and transaction_amt<>0 then N'סכום נרשם בטעות'
when transaction_type in (1,3,4,5) then N'בירור מידע'
when transaction_type = 2 then N'משיכה'
when transaction_type = 6 then N'פעולה בוטלה'
else N'לא ידוע'
end as Transaction_Desc
from Atm_trans
-- Q6
select
customer_id
from Atm_trans
where (transaction_duration>30 or error_message is not null)
and
(transaction_datetime between dateadd(dd,-10,getdate()) and getdate())
group by customer_id
having count(*)>3
-- Q7
update atm_machines
set manufacturer_id=substring(atm_type,1,3)
-- Q8 - א

-- Q8 - ב

-- Q8 - ג

-- Q8 - ד

-- Q8 - ה

-- Q9
א. פרוצדורה GETX מקבלת סכום וסוג מטבע ומחזירה את הסכום מומר לפי שע"ח של אותו מטבע (המרה לשקלים)
ב. פרוצדורה שמדפיסה למסך מציגה את כל העובדים מטבלת EMP1 (לפי EMPID עולה) כאשר לכל עובד מוצג : מספרו + סכום המשכורת שלו בשקלים על בסיס שער החליפין של כל עובד.
הפרוצדורה רצה בלולאה ממספר העובד הנמוך ביותר עד למקסימלי כאשר לכל עובד מחושבת המשכורת בשקלים על בסיס הפונקציה GETX לפי שער החליפין שלו.
ג.
A. @CalculatedAmount
B. @CurrentEmpId
C. @Currency
D. @TotalAmt
댓글