SQL Count Function - SQL Training Online - Quick Tips Ep13

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hey joey blue here and i want to talk about the count function so the count function will give you a count of different things in this case the first one i want to run is we're going to look at the employee table and we know there's 14 records there but we're just going to say count star i use this a lot of times to see how many records are in a table and so we've got 14 records in that table so the count will just count the number of records now there's a couple of other things we can do with it though we could filter in this case we're job equals clerk and since it's a string since it's a string we want to put ticks around it we'll execute that and so we know there's four rows but if we put a count star it would tell us there's four rows so maybe there's a hundred thousand and and we can't just visually look at it and the count star would help us there so we filtered that now let's go and get rid of our filter let's go check check out our table again and what i want to do this time is i want to know how many different jobs there are so let's first do count job okay and i get 14. well is that the right answer 14 different jobs what did it just do there so let's look at the whole table what it did was look for columns that actually had a value well all these all of these rows have a value for job so what we really want to do is we want to know what distinct jobs are there and the way you do that is use the count function with a distinct clause distinct job so now it'll count and give us the distinct jobs so we've executed that we've got five so let's go back and verify that we know what that's doing if we look at jobs there's a clerk that's one there's a salesman that's two there's a manager that's three there's an analyst that's four and a present that's five so there's five distinct jobs so now let's just do a count of this manager field and see what happens so if we execute that we only get 13. but there's 14 rows in our table so what is happening there well in this case it doesn't count null values and so throws that out and only counts the 13 records that actually have a value same thing will happen over here on commission if we do a count of commission you can see there's quite a few nulls here and since i probably didn't spell that right there we go and so we've got actually four people that have a commission and so that is an introduction to the count function within the sql language
Info
Channel: Joey Blue
Views: 45,858
Rating: 4.9358287 out of 5
Keywords: sql count, SQL (Programming Language), Software, Technology, Training (Industry), Data, microsoft, sql, server, 2012, count, function, course, tutorial, class, tip, trick
Id: yY0Go4a4IZU
Channel Id: undefined
Length: 3min 32sec (212 seconds)
Published: Tue May 15 2012
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.