Independent Column Calculation












0















New to SQL Server (T-SQL) and I am not able to find an answer to this question by searching online.



I am trying to write a query that will give me a max date and a count of events since that date in another column. The query I have so far is:



SELECT 
[EmployeeKey], MAX([EvaluationDateTime]) AS [LastFailDate]
FROM
[DataWarehouse].[quality].[FactEvaluation_Current]
WHERE
EvaluationScoreTotal < 80.00
GROUP BY
[EmployeeKey];


I now need to add an additional column that will count all the events from the date returned as LastFailDate but I'm not sure where to add this into this query so that it won't be affected by the WHERE clause?



I think I need something like



SELECT 
COUNT[EvaluationDateTime]
FROM
[DataWarehouse].[quality].[FactEvaluation_Current]
WHERE
[EvaluationDateTime] > [LastFailDate]


Any help or direction of where I can find the answer to this would be greatly appreciated.



Thanks










share|improve this question

























  • Welcome to Stack Overflow! In order to ask a great question, and get the most help from other users, it needs to be Minimal, Complete, and Verifiable example. This question is already Minimal and Complete, but missing the Verifiable example. Can you provide some sample data, and expected output?

    – tarheel
    Nov 26 '18 at 2:18
















0















New to SQL Server (T-SQL) and I am not able to find an answer to this question by searching online.



I am trying to write a query that will give me a max date and a count of events since that date in another column. The query I have so far is:



SELECT 
[EmployeeKey], MAX([EvaluationDateTime]) AS [LastFailDate]
FROM
[DataWarehouse].[quality].[FactEvaluation_Current]
WHERE
EvaluationScoreTotal < 80.00
GROUP BY
[EmployeeKey];


I now need to add an additional column that will count all the events from the date returned as LastFailDate but I'm not sure where to add this into this query so that it won't be affected by the WHERE clause?



I think I need something like



SELECT 
COUNT[EvaluationDateTime]
FROM
[DataWarehouse].[quality].[FactEvaluation_Current]
WHERE
[EvaluationDateTime] > [LastFailDate]


Any help or direction of where I can find the answer to this would be greatly appreciated.



Thanks










share|improve this question

























  • Welcome to Stack Overflow! In order to ask a great question, and get the most help from other users, it needs to be Minimal, Complete, and Verifiable example. This question is already Minimal and Complete, but missing the Verifiable example. Can you provide some sample data, and expected output?

    – tarheel
    Nov 26 '18 at 2:18














0












0








0








New to SQL Server (T-SQL) and I am not able to find an answer to this question by searching online.



I am trying to write a query that will give me a max date and a count of events since that date in another column. The query I have so far is:



SELECT 
[EmployeeKey], MAX([EvaluationDateTime]) AS [LastFailDate]
FROM
[DataWarehouse].[quality].[FactEvaluation_Current]
WHERE
EvaluationScoreTotal < 80.00
GROUP BY
[EmployeeKey];


I now need to add an additional column that will count all the events from the date returned as LastFailDate but I'm not sure where to add this into this query so that it won't be affected by the WHERE clause?



I think I need something like



SELECT 
COUNT[EvaluationDateTime]
FROM
[DataWarehouse].[quality].[FactEvaluation_Current]
WHERE
[EvaluationDateTime] > [LastFailDate]


Any help or direction of where I can find the answer to this would be greatly appreciated.



Thanks










share|improve this question
















New to SQL Server (T-SQL) and I am not able to find an answer to this question by searching online.



I am trying to write a query that will give me a max date and a count of events since that date in another column. The query I have so far is:



SELECT 
[EmployeeKey], MAX([EvaluationDateTime]) AS [LastFailDate]
FROM
[DataWarehouse].[quality].[FactEvaluation_Current]
WHERE
EvaluationScoreTotal < 80.00
GROUP BY
[EmployeeKey];


I now need to add an additional column that will count all the events from the date returned as LastFailDate but I'm not sure where to add this into this query so that it won't be affected by the WHERE clause?



I think I need something like



SELECT 
COUNT[EvaluationDateTime]
FROM
[DataWarehouse].[quality].[FactEvaluation_Current]
WHERE
[EvaluationDateTime] > [LastFailDate]


Any help or direction of where I can find the answer to this would be greatly appreciated.



Thanks







sql-server tsql where-clause






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 6:23









marc_s

575k12811111258




575k12811111258










asked Nov 26 '18 at 1:15









Adrian VruinkAdrian Vruink

1




1













  • Welcome to Stack Overflow! In order to ask a great question, and get the most help from other users, it needs to be Minimal, Complete, and Verifiable example. This question is already Minimal and Complete, but missing the Verifiable example. Can you provide some sample data, and expected output?

    – tarheel
    Nov 26 '18 at 2:18



















  • Welcome to Stack Overflow! In order to ask a great question, and get the most help from other users, it needs to be Minimal, Complete, and Verifiable example. This question is already Minimal and Complete, but missing the Verifiable example. Can you provide some sample data, and expected output?

    – tarheel
    Nov 26 '18 at 2:18

















Welcome to Stack Overflow! In order to ask a great question, and get the most help from other users, it needs to be Minimal, Complete, and Verifiable example. This question is already Minimal and Complete, but missing the Verifiable example. Can you provide some sample data, and expected output?

– tarheel
Nov 26 '18 at 2:18





Welcome to Stack Overflow! In order to ask a great question, and get the most help from other users, it needs to be Minimal, Complete, and Verifiable example. This question is already Minimal and Complete, but missing the Verifiable example. Can you provide some sample data, and expected output?

– tarheel
Nov 26 '18 at 2:18












1 Answer
1






active

oldest

votes


















0














I think below query gives what you want.



 SELECT * FROM 
(
SELECT [EmployeeKey], MAX([EvaluationDateTime]) as [LastFailDate],COUNT[EvaluationDateTime] as [Count_LastFailDate]
FROM [DataWarehouse].[quality].[FactEvaluation_Current]
WHERE EvaluationScoreTotal < 80.00
GROUP BY [EmployeeKey]
)CNT
WHERE [EvaluationDateTime] > [LastFailDate];


But if you want more appropriate answer. Give DDL with sample data.






share|improve this answer


























  • I get an "Invalid column name 'LastFailDate'." error. I think this is because LastFailDate is not a column which exist in my data It is created in the first column of the query? Thanks for your help.

    – Adrian Vruink
    Nov 26 '18 at 2:12











  • Thanks. I edited my answer. Give sample data to give accurate answer.

    – saravanatn
    Nov 26 '18 at 2:19











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53473633%2findependent-column-calculation%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I think below query gives what you want.



 SELECT * FROM 
(
SELECT [EmployeeKey], MAX([EvaluationDateTime]) as [LastFailDate],COUNT[EvaluationDateTime] as [Count_LastFailDate]
FROM [DataWarehouse].[quality].[FactEvaluation_Current]
WHERE EvaluationScoreTotal < 80.00
GROUP BY [EmployeeKey]
)CNT
WHERE [EvaluationDateTime] > [LastFailDate];


But if you want more appropriate answer. Give DDL with sample data.






share|improve this answer


























  • I get an "Invalid column name 'LastFailDate'." error. I think this is because LastFailDate is not a column which exist in my data It is created in the first column of the query? Thanks for your help.

    – Adrian Vruink
    Nov 26 '18 at 2:12











  • Thanks. I edited my answer. Give sample data to give accurate answer.

    – saravanatn
    Nov 26 '18 at 2:19
















0














I think below query gives what you want.



 SELECT * FROM 
(
SELECT [EmployeeKey], MAX([EvaluationDateTime]) as [LastFailDate],COUNT[EvaluationDateTime] as [Count_LastFailDate]
FROM [DataWarehouse].[quality].[FactEvaluation_Current]
WHERE EvaluationScoreTotal < 80.00
GROUP BY [EmployeeKey]
)CNT
WHERE [EvaluationDateTime] > [LastFailDate];


But if you want more appropriate answer. Give DDL with sample data.






share|improve this answer


























  • I get an "Invalid column name 'LastFailDate'." error. I think this is because LastFailDate is not a column which exist in my data It is created in the first column of the query? Thanks for your help.

    – Adrian Vruink
    Nov 26 '18 at 2:12











  • Thanks. I edited my answer. Give sample data to give accurate answer.

    – saravanatn
    Nov 26 '18 at 2:19














0












0








0







I think below query gives what you want.



 SELECT * FROM 
(
SELECT [EmployeeKey], MAX([EvaluationDateTime]) as [LastFailDate],COUNT[EvaluationDateTime] as [Count_LastFailDate]
FROM [DataWarehouse].[quality].[FactEvaluation_Current]
WHERE EvaluationScoreTotal < 80.00
GROUP BY [EmployeeKey]
)CNT
WHERE [EvaluationDateTime] > [LastFailDate];


But if you want more appropriate answer. Give DDL with sample data.






share|improve this answer















I think below query gives what you want.



 SELECT * FROM 
(
SELECT [EmployeeKey], MAX([EvaluationDateTime]) as [LastFailDate],COUNT[EvaluationDateTime] as [Count_LastFailDate]
FROM [DataWarehouse].[quality].[FactEvaluation_Current]
WHERE EvaluationScoreTotal < 80.00
GROUP BY [EmployeeKey]
)CNT
WHERE [EvaluationDateTime] > [LastFailDate];


But if you want more appropriate answer. Give DDL with sample data.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 26 '18 at 2:18

























answered Nov 26 '18 at 2:04









saravanatnsaravanatn

43627




43627













  • I get an "Invalid column name 'LastFailDate'." error. I think this is because LastFailDate is not a column which exist in my data It is created in the first column of the query? Thanks for your help.

    – Adrian Vruink
    Nov 26 '18 at 2:12











  • Thanks. I edited my answer. Give sample data to give accurate answer.

    – saravanatn
    Nov 26 '18 at 2:19



















  • I get an "Invalid column name 'LastFailDate'." error. I think this is because LastFailDate is not a column which exist in my data It is created in the first column of the query? Thanks for your help.

    – Adrian Vruink
    Nov 26 '18 at 2:12











  • Thanks. I edited my answer. Give sample data to give accurate answer.

    – saravanatn
    Nov 26 '18 at 2:19

















I get an "Invalid column name 'LastFailDate'." error. I think this is because LastFailDate is not a column which exist in my data It is created in the first column of the query? Thanks for your help.

– Adrian Vruink
Nov 26 '18 at 2:12





I get an "Invalid column name 'LastFailDate'." error. I think this is because LastFailDate is not a column which exist in my data It is created in the first column of the query? Thanks for your help.

– Adrian Vruink
Nov 26 '18 at 2:12













Thanks. I edited my answer. Give sample data to give accurate answer.

– saravanatn
Nov 26 '18 at 2:19





Thanks. I edited my answer. Give sample data to give accurate answer.

– saravanatn
Nov 26 '18 at 2:19


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53473633%2findependent-column-calculation%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Lallio

Unable to find Lightning Node

Futebolista