Can't find the total in and out of business hours with COUTN CASEtsql : is it possible to do nested case statements in a select?coldfusion count case error depending on datasourceSAS Enterprise Guide Count IFHow do I count distinct and total users and logins by date range across two tables?How to use case statement with select and group bySQL calculating percentage over COUNTtwo counts in the same rowRPAD and CASE statment - Oracle SQL - Missing Right Parenthesis ErrorSQL query syntax in CASE WHEN ELSE END to countDistinct Count when using Case When Statement in SQL Server
How can AnyDVD destroy a DVD drive?
Novel set in the future, children cannot change the class they are born into, one class is made uneducated by associating books with pain
How can a company compel a W2 employee to sign a non-compete agreement?
Shortest way to get an EOF Error
How should I tell a professor the answer to something he doesn't know?
How can I find out a substance name based on its structural formula?
Knights and knaves puzzler
How to respond when insulted by a grad student in a different department?
What is the German word for: "It only works when I try to show you how it does not work"?
How to protect my Wi-Fi password from being displayed by Android phones when sharing it with QR code?
Closed unit ball of an infinite-dimensional Banach space is not compact
How to handle shared mortgage payment if one person can't pay their share?
Why is it popular to teach modulus via the example of mod 12 and analogue clocks?
Planet that goes through its entire history in a matter of Earth days
Tikz arrows not showing correctly
I didn't do any exit passport control when leaving Japan. What should I do?
Hieroglyphs numerals
'The Kukhtarev's model' or 'Kukhtarev's model' ('John's car' or 'The John's car')?
SSD or HDD for server
Would a physician with migraine better treat their patients?
Why is `decltype(static_cast<T>(...))` not always `T`?
Is it true that if we start a sentence with 'the', this 'the' can be omitted?
Which collation should I use for biblical Hebrew?
How can a "proper" function have a vertical slope?
Can't find the total in and out of business hours with COUTN CASE
tsql : is it possible to do nested case statements in a select?coldfusion count case error depending on datasourceSAS Enterprise Guide Count IFHow do I count distinct and total users and logins by date range across two tables?How to use case statement with select and group bySQL calculating percentage over COUNTtwo counts in the same rowRPAD and CASE statment - Oracle SQL - Missing Right Parenthesis ErrorSQL query syntax in CASE WHEN ELSE END to countDistinct Count when using Case When Statement in SQL Server
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
I am trying to make working the COUNT CASE WHEN
statement.
I want to calculate the total between 8-17h and another total outside these hours. My query below always return the grand total.
SELECT DISTINCT tSource,
COUNT(case when (tTime between '08:00:00' and '17:00:00') then 1 else 0 end) as tIN,
COUNT(case when (tTime not between '08:00:00' and '17:00:00') then 1 else 0 end) as tOUT
FROM @tTable
tTotal tIN tOUT
28 13 15
4167 1167 3000
count case case-when
add a comment
|
I am trying to make working the COUNT CASE WHEN
statement.
I want to calculate the total between 8-17h and another total outside these hours. My query below always return the grand total.
SELECT DISTINCT tSource,
COUNT(case when (tTime between '08:00:00' and '17:00:00') then 1 else 0 end) as tIN,
COUNT(case when (tTime not between '08:00:00' and '17:00:00') then 1 else 0 end) as tOUT
FROM @tTable
tTotal tIN tOUT
28 13 15
4167 1167 3000
count case case-when
1
TrySUM
instead ofCOUNT
. Also, it's helpful to tag your post with the specific database you're using; you'll get more useful answers that way.
– A. S. K.
Mar 28 at 21:56
add a comment
|
I am trying to make working the COUNT CASE WHEN
statement.
I want to calculate the total between 8-17h and another total outside these hours. My query below always return the grand total.
SELECT DISTINCT tSource,
COUNT(case when (tTime between '08:00:00' and '17:00:00') then 1 else 0 end) as tIN,
COUNT(case when (tTime not between '08:00:00' and '17:00:00') then 1 else 0 end) as tOUT
FROM @tTable
tTotal tIN tOUT
28 13 15
4167 1167 3000
count case case-when
I am trying to make working the COUNT CASE WHEN
statement.
I want to calculate the total between 8-17h and another total outside these hours. My query below always return the grand total.
SELECT DISTINCT tSource,
COUNT(case when (tTime between '08:00:00' and '17:00:00') then 1 else 0 end) as tIN,
COUNT(case when (tTime not between '08:00:00' and '17:00:00') then 1 else 0 end) as tOUT
FROM @tTable
tTotal tIN tOUT
28 13 15
4167 1167 3000
count case case-when
count case case-when
edited Mar 29 at 1:14
halfelf
7,10011 gold badges36 silver badges50 bronze badges
7,10011 gold badges36 silver badges50 bronze badges
asked Mar 28 at 21:23
Eric LiEric Li
11 bronze badge
11 bronze badge
1
TrySUM
instead ofCOUNT
. Also, it's helpful to tag your post with the specific database you're using; you'll get more useful answers that way.
– A. S. K.
Mar 28 at 21:56
add a comment
|
1
TrySUM
instead ofCOUNT
. Also, it's helpful to tag your post with the specific database you're using; you'll get more useful answers that way.
– A. S. K.
Mar 28 at 21:56
1
1
Try
SUM
instead of COUNT
. Also, it's helpful to tag your post with the specific database you're using; you'll get more useful answers that way.– A. S. K.
Mar 28 at 21:56
Try
SUM
instead of COUNT
. Also, it's helpful to tag your post with the specific database you're using; you'll get more useful answers that way.– A. S. K.
Mar 28 at 21:56
add a comment
|
0
active
oldest
votes
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/4.0/"u003ecc by-sa 4.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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55407055%2fcant-find-the-total-in-and-out-of-business-hours-with-coutn-case%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55407055%2fcant-find-the-total-in-and-out-of-business-hours-with-coutn-case%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
Try
SUM
instead ofCOUNT
. Also, it's helpful to tag your post with the specific database you're using; you'll get more useful answers that way.– A. S. K.
Mar 28 at 21:56