Assignment-6: 1. Differentiate Aggregate Function and Scalar Function
Assignment-6: 1. Differentiate Aggregate Function and Scalar Function
COUNT(*) COUNT()
Counts the rows in table Counts the entries in a column-ignoring null
values
SELECT COUNT (*) val_count CREATE TABLE t(
FROM t; Val int
);
Output: INSERT INTO t(val)
VALUES(1),(2),(2),(3),(NULL),(NULL),(4),(5);
val_count
SELECT val FROM t;
-------------
8 Output:
Val
-------------
(1 row affected) 1
2
3
NULL
NULL
4
5
The TRUNCATE() function is used to return the value of X truncated to D number of decimal
places. If D is 0, then the decimal point is removed. If D is negative, then D number of values in
the integer part of the value is truncated. Consider the following example –
+----------------------+
| TRUNCATE(7.536432,2) |
+----------------------+
| 7.53 |
+----------------------+
The ROUND() function returns X rounded to the nearest integer. If a second argument, D, is
supplied, then the function returns X rounded to D decimal places. D must be positive or all
digits to the right of the decimal point will be removed. Consider the following example −
mysql>SELECT ROUND(5.693893);
+---------------------------------------------------------+
| ROUND(5.693893) |
+---------------------------------------------------------+
| 6 |
+---------------------------------------------------------+
mysql>SELECT ROUND(5.693893,2);
+---------------------------------------------------------+
| ROUND(5.693893,2) |
+---------------------------------------------------------+
| 5.69 |
+---------------------------------------------------------+
REPLACE (char,search_string,replace_string)
If value for replace_string is not specify, the search_string value, when found, is removed.
Possible input can be any character data types, like CHAR, VARCHAR2,NCHAR,CLOB.
SELECT REPLACE('COMPUTER','OM','AB')
FROM dual;
Output
-----------
CABPUTER
Translate:
TRANSLATE (string,if,then)
SELECT TRANSLATE(1256364,2345678,'BDEFGHI')
FROM dual;
Output
----------
BFGDGE
+------+
| Age |
+------+
| 8|
+------+
1 row in set (0.00 sec)
--- 196170307055