客户:
staffID | fname | lname
inStorePay:
inStorePaymnet | hourlyPayment | staffId
如何连接表,以便将结果放在一个表中?
Select hourlyPayment, (Count(hourlyPayment)* 100 / (Select Count(*) From
inStorePay)) as rate
From inStorePay
Group By hourlyPayment
SELECT S.fname,S.lname, I.hourlyPayment
FROM Staff S, inStorePay I
WHERE S.staffID ='S0984'
答案 0 :(得分:0)
希望此代码可以帮助您
--Here Dbo.[InStorePay](StaffID) column depends on Dbo.[Customer](StaffID) ,Now you can join above tables Using StaffID column
CREATE TABLE [dbo].[Customer](
StaffID INT IDENTITY,
Fname VARCHAR(200),
Lname VARCHAR(200)
PRIMARY KEY CLUSTERED
(
[staffID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[InStorePay](
InStorePayId INT IDENTITY,
StaffID INT,
InStorePaymnet Money,
HourlyPayment Money
PRIMARY KEY CLUSTERED
(
[InStorePayId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [InStorePay] ADD CONSTRAINT Fk_InStorePay_Customer FOREIGN Key (StaffID) REFERENCES Dbo.[Customer](StaffID)
答案 1 :(得分:0)