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;









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









share|improve this question























  • 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

















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









share|improve this question























  • 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













0












0








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









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question



share|improve this question








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





    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












  • 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







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












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
);



);














draft saved

draft discarded
















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
















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%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





















































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

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현