--------Burhon Baqoyev, [7/15/2022 5:38 AM]
SELECT empid, DATEADD(dd, N, '2016-12-06') AS [DAY]
FROM HR.Employees CROSS JOIN Nums
WHERE n BETWEEN 0 AND 4
ORDER BY empid;
------Burhon Baqoyev, [7/15/2022 5:39 AM]
SELECT empid,
DATEADD(DAY, n, '2016-06-11') as dt
FROM HR.Employees,
(
SELECT TOP 5 n
FROM dbo.Nums
) as ndbo
ORDER BY empid
SELECT empid, DATEADD(dd, N, '2016-12-06') AS [DAY]
FROM HR.Employees CROSS JOIN Nums
WHERE n BETWEEN 0 AND 4
ORDER BY empid;
------Burhon Baqoyev, [7/15/2022 5:39 AM]
SELECT empid,
DATEADD(DAY, n, '2016-06-11') as dt
FROM HR.Employees,
(
SELECT TOP 5 n
FROM dbo.Nums
) as ndbo
ORDER BY empid
Forwarded from Dasturlash hayoti️️ ️
Forwarded from Adam H H
SQLPracticeProblems_SQLServer-1-54.pdf
594.1 KB
Forwarded from Deleted Account
Expert_T_SQL_Window_Functions_in_SQL_Server_2019_The_Hidden_Secret.pdf
9.6 MB
#CHALLANGE
create table Hackers(
hacker_id int,
name nvarchar(99)
)
insert into Hackers values
(5077,'Rose'),
(21283,'Angela'),
(62743,'Frank'),
(88255,'Patrick'),
(96196,'Lisa')
create table Challenges(
challenge_id int,
hacker_id int
)
insert into Challenges values
(61654,5077),
(58302,21283),
(40587,88255),
(29477,5077),
(1220,21283),
(69514, 21283),
(46561,62743),
(58077,62743),
(18483,88255),
(76766,21283),
(52382,5077),
(74467,21283),
(33625,96196),
(26053,88255),
(42665,62743),
(12859,62743),
(70094,21283),
(34599,88255),
(54680,88255),
(61881,5077)
select * from Hackers
select * from Challenges
with AABB as(
select c.hacker_id,h.name,c.nums, ROW_NUMBER() over (partition by c.nums order by c.nums) as son
from (select hacker_id, count(challenge_id) as nums from Challenges group by hacker_id) c
inner join Hackers h
on h.hacker_id=c.hacker_id
)
select hacker_id,name,nums from AABB
where name in (select case
when nums in (select nums from AABB where son>1) and nums=(select max(nums) from AABB) then name
when nums in (select nums from AABB where son>1) and nums!=(select max(nums) from AABB) then null
else name
end
from AABB)
create table Hackers(
hacker_id int,
name nvarchar(99)
)
insert into Hackers values
(5077,'Rose'),
(21283,'Angela'),
(62743,'Frank'),
(88255,'Patrick'),
(96196,'Lisa')
create table Challenges(
challenge_id int,
hacker_id int
)
insert into Challenges values
(61654,5077),
(58302,21283),
(40587,88255),
(29477,5077),
(1220,21283),
(69514, 21283),
(46561,62743),
(58077,62743),
(18483,88255),
(76766,21283),
(52382,5077),
(74467,21283),
(33625,96196),
(26053,88255),
(42665,62743),
(12859,62743),
(70094,21283),
(34599,88255),
(54680,88255),
(61881,5077)
select * from Hackers
select * from Challenges
with AABB as(
select c.hacker_id,h.name,c.nums, ROW_NUMBER() over (partition by c.nums order by c.nums) as son
from (select hacker_id, count(challenge_id) as nums from Challenges group by hacker_id) c
inner join Hackers h
on h.hacker_id=c.hacker_id
)
select hacker_id,name,nums from AABB
where name in (select case
when nums in (select nums from AABB where son>1) and nums=(select max(nums) from AABB) then name
when nums in (select nums from AABB where son>1) and nums!=(select max(nums) from AABB) then null
else name
end
from AABB)
👍3