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 7778657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:27:11+00:00 2026-06-01T18:27:11+00:00

My SQL SELECT nce.id, nce.send, count( * ) AS total FROM `newsletter_email` nce WHERE

  • 0

My SQL

SELECT nce.id, nce.send, count( * ) AS total
FROM `newsletter_email` nce
WHERE 1
GROUP BY nce.id, nce.send

Produces the result:

id  send    total
4   0       6
4   1       1
5   0       2
6   1       7
7   1       4
8   0       2
8   1       4
9   1       1

But I want the result to be:

id  send    no_send     total
4   6       1           7
5   0       2           2
6   7       0           7
7   4       0           4
8   4       2           6
9   1       0           1

I have tried several ways but it did not give the expected result. Can you help?

  • 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-06-01T18:27:12+00:00Added an answer on June 1, 2026 at 6:27 pm

    Assuming Send has value of 1 for send and 0 for no_send, you can simply sum values of send:

    SELECT nce.id, 
       sum(nce.send) as Send, 
       sum(1 - nce.send) as NO_send, 
       count(nce.send) as Total
    FROM `newsletter_email` nce
    GROUP BY nce.id
    

    However, general pattern would be:

    SELECT nce.id, 
       sum(case when nce.send = 1 then 1 end) as Send, 
       sum(case when nce.send = 0 then 1 end) as NO_send, 
       count(nce.send) as Total
    FROM `newsletter_email` nce
    GROUP BY nce.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this SQL: select o.prod_id, SUM(o.[count]) as [count] into #otgr from otgr o
I want to select sql: SELECT year-month from table group by year-month AND order
I have next sql select site_id,count from tags where match (tag) against ('statistici' in
Here is my SQL: SELECT COUNT(id), CONCAT(YEAR(created_at), '-', MONTH(created_at), '-', DAY(created_at)) FROM my_table GROUP
I have an sql: SELECT Sum(Field1), Sum(Field2), Sum(Field1)+Sum(Field2) FROM Table GROUP BY DateField HAVING
SQL : SELECT COUNT(usr.id) as `total_results` FROM users as usr LEFT JOIN profile as
I have the following SQL: SELECT * FROM [Database].dbo.[TagsPerItem] INNER JOIN [Database].dbo.[Tag] ON [Tag].Id
I have a T-SQL select statement and I want to auto-increment a column in
I have an SQL SELECT query that also uses a GROUP BY , I
I have the following SQL SELECT statement SELECT bar_id, bar_name, town_name, advert_text FROM bar,

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.