I have large tables where data quality rules are running. There is a field called "RunNumber" to identify if data is appended- it can have a value of 1 or 2(but not limited to just 2). We don't have a Group By statement. Searching here, I found questions titled "SQL Max(date) without group by" and "SQL max without group by", and tried putting the MAX statement as below, but don't think that it's working correctly because of the output. Thanks in advance!
SELECT
MAX(RunNumber),
CAST(SUM(FirstName) AS INT) AS FirstName,
CAST(SUM(LastName) AS INT) AS LastName,
CAST(SUM(State) AS INT) AS State
FROM
(SELECT
CASE WHEN FirstName IS NULL THEN 1 ELSE 0 END FirstName,
CASE WHEN LastName IS NULL THEN 1 ELSE 0 END LastName,
CASE WHEN State IS NULL THEN 1 ELSE 0 END State
FROM
Table.Customers (nolock)
WHERE
DateOfRecord = '5/1/2023') a;
The output that I get is:
[No name 1] | FirstName | LastName | State |
---|---|---|---|
0 | 5000 | 7500 | 9000 |
2条答案
按热度按时间bwleehnv1#
Seems like a conditional aggregation should do the trick
ttygqcqt2#
I understood something from your question, you want to do calculations for each RunNumber
Base Data: