SQL Server Why getting same result from two queries with different conditions? [closed]

92vpleto  于 2023-10-15  发布在  其他
关注(0)|答案(1)|浏览(92)

Closed. This question needs debugging details . It is not currently accepting answers.

Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem . This will help others answer the question.

Closed 9 hours ago.
Improve this question

I try to get active and inactive customers from tblcust table. I have over 82,000 inactive customers with 53,000 active ones, but both are return 53,000.

DECLARE @active int;
DECLARE @inactive int;
    
SELECT 
    @active = COUNT(*) 
FROM 
    (SELECT c.id 
     FROM tblcust c 
     WHERE c.status = 1) AS Actives;
    
SELECT 
    @inactive = COUNT(*) 
FROM 
    (SELECT * 
     FROM tblcust 
     WHERE status <> 1) AS Inactives;
kfgdxczn

kfgdxczn1#

Without access to the data it's not possible to find out the error.

Have you tried just a simple query to see the ratio:

select status, count(*) cnt from tblcust group by status;

It's algo good to keep in mind if status is not a integer = and <> might sometimes do wonky things to strings as well.

相关问题