Я пытаюсь вернуть t1.firstname, t1.lastname, t1.city, t1.stateprovince, и я хотел бы вернуть t2.amount, t2.restaurantname, t2.restaurantnum, t2.datekey и t2.amountа также.
Вот мой код:
SELECT DISTINCT
t1.[FirstName] AS FirstName,
t1.[LastName] AS LastName,
t1.[City] AS City,
t1.[StateProvince] AS StateProvince
FROM
Database.dbo.CustomerData t1
JOIN
(SELECT DISTINCT
MAX(t2.[Amount]) AS Amount,
MAX(t2.[Account]) AS Account,
MAX(t2.[CardNumber]) AS CardNumber,
MAX(t2.[RestaurantNum]) AS RestaurantNum,
MAX(t2.[RestaurantName]) AS RestaurantName,
MAX(t2.[DateKey]) AS DateKey,
SUM([t2].[Amount]) AS Total_Spend
FROM
gift.TransactionItems t2
GROUP BY
t2.[Amount],
t2.[RestaurantNum],
t2.[RestaurantName],
t2.[DateKey],
t2.[AccountID],
t2.[TransactionID]) t2 ON t1.[CardNumber] = t2.[CardNumber]
WHERE
[FirstName] IS NOT NULL
AND [LastName] IS NOT NULL
AND [EmailFailed] IS NULL
AND [IsRegistered] = 'Yes'
AND [DateKey] BETWEEN 20180601 AND 20181213
AND t2.[Account] = 'Dollars_Spent_Accrued'
Возможно ли это?В настоящее время он возвращает только t1.firstname, t1.lastname, t1.city и t1.stateprovince.