Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6011921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:19:44+00:00 2026-05-23T02:19:44+00:00

I am using SUM ( CASE WHEN ) to count number of Yes and

  • 0

I am using SUM ( CASE WHEN ) to count number of Yes and No, it work fine.

I am havin problem counting number of matching mobile number from two tables. It dont seem to be counting correctly.

There is a MobileNO field in dairy table and mobile field in the sales table

SELECT 
       D.Username, 
       SUM(CASE WHEN D.type = 'Yes' THEN 1 ELSE 0 END) as Yes, 
       SUM(CASE WHEN D.type = 'No' THEN 1 ELSE 0 END) as No, 
       SUM(CASE WHEN D.type = '' THEN 1 ELSE 0 END) as Other, 
       (SELECT SUM(CASE WHEN D.MobileNo = S.mobile THEN 1 ELSE 0 END) from sales as S) as Sales, 
       COUNT(*) as TOTAL FROM dairy as D 
WHERE source = 'Company' AND UNIX_TIMESTAMP(CheckDate) >= 1293840000 AND UNIX_TIMESTAMP(CheckDate) <= 1322697600 
group by D.Username order by TOTAL DESC 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:19:45+00:00Added an answer on May 23, 2026 at 2:19 am
    SELECT 
           D.Username, 
           SUM(CASE WHEN D.type = 'Yes' THEN 1 ELSE 0 END) as Yes, 
           SUM(CASE WHEN D.type = 'No' THEN 1 ELSE 0 END) as No, 
           SUM(CASE WHEN D.type = '' THEN 1 ELSE 0 END) as Other, 
           SUM(CASE WHEN S.mobile IS NULL THEN 0 ELSE 1 END) as Sales, 
           COUNT(*) as TOTAL 
    FROM dairy as D 
    LEFT JOIN (SELECT DISTINCT mobile FROM sales) as S ON D.MobileNo = S.mobile
    WHERE source = 'Company' AND UNIX_TIMESTAMP(CheckDate) >= 1293840000 AND UNIX_TIMESTAMP(CheckDate) <= 1322697600 
    group by D.Username order by TOTAL DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there some way to sum up two different tweet number from two different
I'm looking for help using sum() in my SQL query: SELECT links.id, count(DISTINCT stats.id)
I am using this code to sum values from multiple radio buttons : $(document).ready(function(){
This is my base query select distinct a.projects , case when(billing_fy!=0) then(select round(((sum(cost_project)/(sum(billing_fy)/((10/12)*365)))),2) from
I am calculating percentages in Analysis Services 2008 using MDX by dividing the sum
i am getting an error while querying this select statement. $comments = dbgetvar(SELECT SUM(CASE
The problem I am having seems to come from my where clause and hardcoding.
I'm using Informix version 11.50.FC6 via iSql I'm giving the result of a CASE
I am using jquery calculation to do a sum on one of my client
Please look at the below query select DATEADD(wk, DATEDIFF(wk, 6, creation_ts), 6) creation_ts ,sum(case

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.