Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

Counting number of rows that fit certain criteria

$
0
0

This seems quite basic and according to what I have found on W3 schools, I am setting this up correctly. However, it is returning incorrect result sets.

Below is the code that I am using. The goal is to have it return the count of rows that fit certain criteria. In this area = '000510' and ownership = '50' and the naicscode beginning with 11 and 21. Currently it returns 252, If i put the data set in excel and narrow it down using filters, it returns 4 rows. 

Do I need to add another clause or a Select Distinct?

Text
select count (*) from dbo.stfirms201701
where area = '000510' and ownership ='50' and naicscode like '11%' or naicscode like '21%'

Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>