Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Help counting rows

$
0
0
I need some help with a select statement joining file1 to file2. File 1 may have 0, 1, or many corresponding rows in file2. I need to count the corresponding rows in table2. Table2 also has a Boolean column and I need to count the number of rows where it is true. So I need to count the total number of matching rows and the count of those that are set to true. This is an example of what I have so far. I had to add each column being selected into a Group by to make it work, but I do not know why. Is there some other way this should be set up. I am obviously not an SQL guy, but I would really appreciate some help.SELECT c.CarId, c.CarName, c.CarColor, COUNT(t.TrailerId) as trailerCount, (add count of boolian, say t.TrailerFull is true)FROM Car cLEFT JOIN Trailer t on t.CarId = c.CarIdGROUP BY c.CarId, c.CarName, c.CarColor

Viewing all articles
Browse latest Browse all 3145

Trending Articles