Another aggregate function other than SUM is COUNT. The purpose of COUNT function is to return the number of rows found in a table.
For example, if we want to count how many sales transaction are there in our SALES table found below, we will used the query below.
Query SQL COUNT
select COUNT(*) from sales;
Output SQL COUNT
The output is 3 since there are only 3 sales transaction in our SALES table.
The COUNT(*) on the above output is not quite readable. There will be cases wherein you need to use an alias to easily identify a certain column returned using a function. Or perhaps to access the returned output later in php. To use an alias, use the as keyword followed by your alias. I provided an example below. The nooftrans is your now your new column name that contains the result of the COUNT function.
select COUNT(*) as nooftrans from sales;
Hope this helps! Feel free to post a comment below for questions. ^_^
No comments:
Post a Comment