Select employee_id, first_name, last_name,department_id,
(Select department_name From dbo.departments
Where department_id=e.department_id ) as department_name
From employees e.
(Select department_name From dbo.departments
Where department_id=e.department_id ) as department_name
From employees e.
#Subquery table create table mahsulot(
id int primary key identity(1,1),
nomi nvarchar(99),
malumot nvarchar(99)
)
insert into mahsulot values
('tv','52 dyumli LCD'),
('Notebook','ofisniy oddiy'),
('Desktop','Stolniy kompyuter')
create table sotuv (
id int primary key identity,
mahsulot_id int not null,
narxi int not null,
soni int not null
)
insert into sotuv values
(3,450,5),
(2,250,7),
(3,450,4),
(3,450,9)
Create Table tblProducts
(
[Id] int identity primary key,
[Name] nvarchar(50),
[Description] nvarchar(250)
)
Create Table tblProductSales
(
Id int primary key identity,
ProductId int foreign key references tblProducts(Id),
UnitPrice int,
QuantitySold int
)
Insert into tblProducts values ('TV', '52 inch black color LCD TV')
Insert into tblProducts values ('Laptop', 'Very thin black color acer laptop')
Insert into tblProducts values ('Desktop', 'HP high performance desktop')
Insert into tblProductSales values(3, 450, 5)
Insert into tblProductSales values(2, 250, 7)
Insert into tblProductSales values(3, 450, 4)
Insert into tblProductSales values(3, 450, 9)
id int primary key identity(1,1),
nomi nvarchar(99),
malumot nvarchar(99)
)
insert into mahsulot values
('tv','52 dyumli LCD'),
('Notebook','ofisniy oddiy'),
('Desktop','Stolniy kompyuter')
create table sotuv (
id int primary key identity,
mahsulot_id int not null,
narxi int not null,
soni int not null
)
insert into sotuv values
(3,450,5),
(2,250,7),
(3,450,4),
(3,450,9)
Create Table tblProducts
(
[Id] int identity primary key,
[Name] nvarchar(50),
[Description] nvarchar(250)
)
Create Table tblProductSales
(
Id int primary key identity,
ProductId int foreign key references tblProducts(Id),
UnitPrice int,
QuantitySold int
)
Insert into tblProducts values ('TV', '52 inch black color LCD TV')
Insert into tblProducts values ('Laptop', 'Very thin black color acer laptop')
Insert into tblProducts values ('Desktop', 'HP high performance desktop')
Insert into tblProductSales values(3, 450, 5)
Insert into tblProductSales values(2, 250, 7)
Insert into tblProductSales values(3, 450, 4)
Insert into tblProductSales values(3, 450, 9)
https://www.w3resource.com/sql-exercises/sql-joins-exercises.php Joinlarni o'rganish uchun yaxshi sayt
w3resource
SQL JOINS - Exercises, Practice, Solution - w3resource
Practice with solution of exercises on SQL JOINS with LEFT JOIN, RIGHT JOIN, LEFT OUTER JOIN, RIGHT OUTER JOIN, FULL OUTER JOIN, SELF JOIN, EQUI JOIN NON EQUI JOIN, CROSS JOIN, NATURAL JOIN, and more from w3resource.
Select nt.CategoryID,SUM(nt.price) price
From (Select pp.CategoryID,pp.ProductID,(
Select
SUM(od.UnitPrice*od.Quantity) price
From dbo.Products p
INNER JOIN dbo.[Order Details] od
on od.ProductID=p.ProductID
where pp.ProductID=p.ProductID) price
From dbo.Products pp
) as nt
Group by nt.CategoryID
From (Select pp.CategoryID,pp.ProductID,(
Select
SUM(od.UnitPrice*od.Quantity) price
From dbo.Products p
INNER JOIN dbo.[Order Details] od
on od.ProductID=p.ProductID
where pp.ProductID=p.ProductID) price
From dbo.Products pp
) as nt
Group by nt.CategoryID