{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Character, Number, Date, and Group functions\n",
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Connecting with the database"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%load_ext sql\n",
"# replace with your own credentials\n",
"%sql ibm_db_sa://my-username:my-password@dashdb-txn-sbox-yp-dal09-03.services.dal.bluemix.net:50000/BLUDB"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### • GROUP FUNCTIONS"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`Group functions` (also called `aggregate functions`) are mathematical functions to operate on sets of rows to give one result per set."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1. AVG Function\n",
"It returns the average of the values in the selected columns. "
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * ibm_db_sa://lzv55210:***@dashdb-txn-sbox-yp-dal09-12.services.dal.bluemix.net:50000/BLUDB\n",
"Done.\n"
]
},
{
"data": {
"text/html": [
"
\n",
" \n",
" country | \n",
" first_name | \n",
" last_name | \n",
" test_score | \n",
"
\n",
" \n",
" United States | \n",
" Marshall | \n",
" Bernadot | \n",
" 54 | \n",
"
\n",
" \n",
" United States | \n",
" Celinda | \n",
" Malkin | \n",
" 51 | \n",
"
\n",
" \n",
" Ukraine | \n",
" Guillermo | \n",
" Furze | \n",
" 53 | \n",
"
\n",
" \n",
" Ukraine | \n",
" Aharon | \n",
" Tunnow | \n",
" 48 | \n",
"
\n",
" \n",
" Russia | \n",
" Bail | \n",
" Goodwin | \n",
" 46 | \n",
"
\n",
" \n",
" Poland | \n",
" Cole | \n",
" Winteringham | \n",
" 49 | \n",
"
\n",
" \n",
" Sweden | \n",
" Emlyn | \n",
" Erricker | \n",
" 55 | \n",
"
\n",
" \n",
" Russia | \n",
" Cathee | \n",
" Sivewright | \n",
" 49 | \n",
"
\n",
" \n",
" Poland | \n",
" Barny | \n",
" Ingerson | \n",
" 57 | \n",
"
\n",
" \n",
" Sweden | \n",
" Sharla | \n",
" Papaccio | \n",
" 55 | \n",
"
\n",
"
"
],
"text/plain": [
"[('United States', 'Marshall', 'Bernadot', 54),\n",
" ('United States', 'Celinda', 'Malkin', 51),\n",
" ('Ukraine', 'Guillermo', 'Furze', 53),\n",
" ('Ukraine', 'Aharon', 'Tunnow', 48),\n",
" ('Russia', 'Bail', 'Goodwin', 46),\n",
" ('Poland', 'Cole', 'Winteringham', 49),\n",
" ('Sweden', 'Emlyn', 'Erricker', 55),\n",
" ('Russia', 'Cathee', 'Sivewright', 49),\n",
" ('Poland', 'Barny', 'Ingerson', 57),\n",
" ('Sweden', 'Sharla', 'Papaccio', 55)]"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql select * from STUDENTS"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * ibm_db_sa://lzv55210:***@dashdb-txn-sbox-yp-dal09-12.services.dal.bluemix.net:50000/BLUDB\n",
"Done.\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" 1 | \n",
"
\n",
" \n",
" 51.700000 | \n",
"
\n",
"
"
],
"text/plain": [
"[(Decimal('51.700000'),)]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql select avg(test_score) from STUDENTS"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * ibm_db_sa://lzv55210:***@dashdb-txn-sbox-yp-dal09-12.services.dal.bluemix.net:50000/BLUDB\n",
"Done.\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" average_marks | \n",
"
\n",
" \n",
" 51.700000 | \n",
"
\n",
"
"
],
"text/plain": [
"[(Decimal('51.700000'),)]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql select avg(test_score) as average_marks from STUDENTS"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2. MIN Function\n",
"Returns the data from the row in which the specified column contains the minimum value."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * ibm_db_sa://lzv55210:***@dashdb-txn-sbox-yp-dal09-12.services.dal.bluemix.net:50000/BLUDB\n",
"Done.\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" min_marks | \n",
"
\n",
" \n",
" 46 | \n",
"
\n",
"
"
],
"text/plain": [
"[(46,)]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql select min(test_score) as min_marks from STUDENTS"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3. MAX Function\n",
"Returns the data of the row in which the specified column contains the maximum value."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * ibm_db_sa://lzv55210:***@dashdb-txn-sbox-yp-dal09-12.services.dal.bluemix.net:50000/BLUDB\n",
"Done.\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" max_marks | \n",
"
\n",
" \n",
" 57 | \n",
"
\n",
"
"
],
"text/plain": [
"[(57,)]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql select max(test_score) as max_marks from STUDENTS"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 4. SUM Function\n",
"Returns the total of all the values in a specified column."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * ibm_db_sa://lzv55210:***@dashdb-txn-sbox-yp-dal09-12.services.dal.bluemix.net:50000/BLUDB\n",
"Done.\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" toal_marks | \n",
"
\n",
" \n",
" 517 | \n",
"
\n",
"
"
],
"text/plain": [
"[(517,)]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql select sum(test_score) as toal_marks from STUDENTS"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 5. COUNT Function\n",
"It adds the number of rows that matches the criteria specified in the select statement."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * ibm_db_sa://lzv55210:***@dashdb-txn-sbox-yp-dal09-12.services.dal.bluemix.net:50000/BLUDB\n",
"Done.\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" no_of_rows | \n",
"
\n",
" \n",
" 10 | \n",
"
\n",
"
"
],
"text/plain": [
"[(Decimal('10'),)]"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql select count(*) as no_of_rows from STUDENTS"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### • CURRENT DATE AND TIME"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The most difficult part when working with dates is to be sure that the format of the date you are trying to insert, matches the format of the date column in the database. As long as your data contains only the date portion, your queries will work as expected. However, if a time portion is involved, it gets complicated."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1. NOW\n",
"This function returns the current date and time of the system."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * ibm_db_sa://lzv55210:***@dashdb-txn-sbox-yp-dal09-12.services.dal.bluemix.net:50000/BLUDB\n",
"Done.\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" current_date_time | \n",
"
\n",
" \n",
" 2020-11-12 10:40:45.698828 | \n",
"
\n",
"
"
],
"text/plain": [
"[(datetime.datetime(2020, 11, 12, 10, 40, 45, 698828),)]"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql select now() as current_date_time from STUDENTS where test_score=54"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2. CURDATE \n",
"Returns the current date of the system."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * ibm_db_sa://lzv55210:***@dashdb-txn-sbox-yp-dal09-12.services.dal.bluemix.net:50000/BLUDB\n",
"Done.\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" 1 | \n",
"
\n",
" \n",
" 2020-11-12 | \n",
"
\n",
"
"
],
"text/plain": [
"[(datetime.date(2020, 11, 12),)]"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql VALUES CURRENT DATE"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3. CURTIME\n",
"Returns the current time of the system."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * ibm_db_sa://lzv55210:***@dashdb-txn-sbox-yp-dal09-12.services.dal.bluemix.net:50000/BLUDB\n",
"Done.\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" 1 | \n",
"
\n",
" \n",
" 10:40:47 | \n",
"
\n",
"
"
],
"text/plain": [
"[(datetime.time(10, 40, 47),)]"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql VALUES CURRENT TIME"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### • CHARACTER FUNCTIONS\n",
"Character functions accept character inputs and can return either characters or number values as output."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1. ASCII\n",
"Returns the ASCII code of the leftmost character of the string passed."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * ibm_db_sa://lzv55210:***@dashdb-txn-sbox-yp-dal09-12.services.dal.bluemix.net:50000/BLUDB\n",
"Done.\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" first_name | \n",
" ascii_fname | \n",
"
\n",
" \n",
" Marshall | \n",
" 77 | \n",
"
\n",
" \n",
" Celinda | \n",
" 67 | \n",
"
\n",
" \n",
" Guillermo | \n",
" 71 | \n",
"
\n",
" \n",
" Aharon | \n",
" 65 | \n",
"
\n",
" \n",
" Bail | \n",
" 66 | \n",
"
\n",
" \n",
" Cole | \n",
" 67 | \n",
"
\n",
" \n",
" Emlyn | \n",
" 69 | \n",
"
\n",
" \n",
" Cathee | \n",
" 67 | \n",
"
\n",
" \n",
" Barny | \n",
" 66 | \n",
"
\n",
" \n",
" Sharla | \n",
" 83 | \n",
"
\n",
"
"
],
"text/plain": [
"[('Marshall', 77),\n",
" ('Celinda', 67),\n",
" ('Guillermo', 71),\n",
" ('Aharon', 65),\n",
" ('Bail', 66),\n",
" ('Cole', 67),\n",
" ('Emlyn', 69),\n",
" ('Cathee', 67),\n",
" ('Barny', 66),\n",
" ('Sharla', 83)]"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql select first_name, ascii(first_name) as ascii_fname from STUDENTS"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2. CHAR\n",
"Returns the character of ineteger."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * ibm_db_sa://lzv55210:***@dashdb-txn-sbox-yp-dal09-12.services.dal.bluemix.net:50000/BLUDB\n",
"Done.\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" 1 | \n",
"
\n",
" \n",
" \u0017 | \n",
"
\n",
"
"
],
"text/plain": [
"[('\\x17',)]"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql VALUES chr('23') "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3. CONCAT\n",
"Returns the string that results from the concatenation of the arguments."
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * ibm_db_sa://lzv55210:***@dashdb-txn-sbox-yp-dal09-12.services.dal.bluemix.net:50000/BLUDB\n",
"Done.\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" name | \n",
"
\n",
" \n",
" MarshallBernadot | \n",
"
\n",
"
"
],
"text/plain": [
"[('MarshallBernadot',)]"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql select concat(first_name, last_name) as name from STUDENTS where test_score=54"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 4. INSTR\n",
"Returns the location of the specified substring in a string."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * ibm_db_sa://lzv55210:***@dashdb-txn-sbox-yp-dal09-12.services.dal.bluemix.net:50000/BLUDB\n",
"Done.\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" at_index | \n",
"
\n",
" \n",
" 4 | \n",
"
\n",
"
"
],
"text/plain": [
"[(4,)]"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql select instr('quadratic', 'dra') as at_index from STUDENTS where test_score=54"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 5. INSERT\n",
"Inserts a substring into a string at the specified position."
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * ibm_db_sa://lzv55210:***@dashdb-txn-sbox-yp-dal09-12.services.dal.bluemix.net:50000/BLUDB\n",
"Done.\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" 1 | \n",
"
\n",
" \n",
" quwhattic | \n",
"
\n",
"
"
],
"text/plain": [
"[('quwhattic',)]"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql select insert('quadratic',3,4, 'what') from STUDENTS where test_score=54"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 6. LENGTH\n",
"Returns the length of the string."
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * ibm_db_sa://lzv55210:***@dashdb-txn-sbox-yp-dal09-12.services.dal.bluemix.net:50000/BLUDB\n",
"Done.\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" first_name | \n",
" length | \n",
"
\n",
" \n",
" Marshall | \n",
" 8 | \n",
"
\n",
" \n",
" Celinda | \n",
" 7 | \n",
"
\n",
" \n",
" Guillermo | \n",
" 9 | \n",
"
\n",
" \n",
" Aharon | \n",
" 6 | \n",
"
\n",
" \n",
" Bail | \n",
" 4 | \n",
"
\n",
" \n",
" Cole | \n",
" 4 | \n",
"
\n",
" \n",
" Emlyn | \n",
" 5 | \n",
"
\n",
" \n",
" Cathee | \n",
" 6 | \n",
"
\n",
" \n",
" Barny | \n",
" 5 | \n",
"
\n",
" \n",
" Sharla | \n",
" 6 | \n",
"
\n",
"
"
],
"text/plain": [
"[('Marshall', 8),\n",
" ('Celinda', 7),\n",
" ('Guillermo', 9),\n",
" ('Aharon', 6),\n",
" ('Bail', 4),\n",
" ('Cole', 4),\n",
" ('Emlyn', 5),\n",
" ('Cathee', 6),\n",
" ('Barny', 5),\n",
" ('Sharla', 6)]"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql select first_name, length(first_name) as length from STUDENTS"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 7. LOWER\n",
"Converts all the letters to lower case."
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * ibm_db_sa://lzv55210:***@dashdb-txn-sbox-yp-dal09-12.services.dal.bluemix.net:50000/BLUDB\n",
"Done.\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" 1 | \n",
"
\n",
" \n",
" hello | \n",
"
\n",
"
"
],
"text/plain": [
"[('hello',)]"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql select lower('HELLO') from STUDENTS where test_score=54"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 8. UPPER\n",
"Converts all the letters to upper case."
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * ibm_db_sa://lzv55210:***@dashdb-txn-sbox-yp-dal09-12.services.dal.bluemix.net:50000/BLUDB\n",
"Done.\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" 1 | \n",
"
\n",
" \n",
" HELLO | \n",
"
\n",
"
"
],
"text/plain": [
"[('HELLO',)]"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql select upper('hello') from STUDENTS where test_score=54"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### • NUMBER FUNCTIONS\n",
"SQL numeric functions are used primarily for numeric manipulation and/or mathematical calculations."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1. POWER (X,Y)\n",
"Returns the value of x raised to the power of y."
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * ibm_db_sa://lzv55210:***@dashdb-txn-sbox-yp-dal09-12.services.dal.bluemix.net:50000/BLUDB\n",
"Done.\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" 1 | \n",
"
\n",
" \n",
" 25 | \n",
"
\n",
"
"
],
"text/plain": [
"[(25,)]"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql VALUES POWER(5, 2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2. Round (M,N)\n",
"Returns M round to N places to the right of decimal."
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * ibm_db_sa://lzv55210:***@dashdb-txn-sbox-yp-dal09-12.services.dal.bluemix.net:50000/BLUDB\n",
"Done.\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" 1 | \n",
"
\n",
" \n",
" 873.700 | \n",
"
\n",
"
"
],
"text/plain": [
"[(Decimal('873.700'),)]"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql VALUES ROUND(873.729, 1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3. SQRT (N)\n",
"Returns the square root of N."
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * ibm_db_sa://lzv55210:***@dashdb-txn-sbox-yp-dal09-12.services.dal.bluemix.net:50000/BLUDB\n",
"Done.\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" 1 | \n",
"
\n",
" \n",
" 5.0 | \n",
"
\n",
"
"
],
"text/plain": [
"[(5.0,)]"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql VALUES SQRT(25)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 4. EXP (N)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * ibm_db_sa://lzv55210:***@dashdb-txn-sbox-yp-dal09-12.services.dal.bluemix.net:50000/BLUDB\n",
"Done.\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" 1 | \n",
"
\n",
" \n",
" 20.085536923187668 | \n",
"
\n",
"
"
],
"text/plain": [
"[(20.085536923187668,)]"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql VALUES EXP(3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 5. MOD (N,M)"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * ibm_db_sa://lzv55210:***@dashdb-txn-sbox-yp-dal09-12.services.dal.bluemix.net:50000/BLUDB\n",
"Done.\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" 1 | \n",
"
\n",
" \n",
" 25 | \n",
"
\n",
"
"
],
"text/plain": [
"[(25,)]"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql VALUES MOD(125, 50)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 6. FLOOR"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * ibm_db_sa://lzv55210:***@dashdb-txn-sbox-yp-dal09-12.services.dal.bluemix.net:50000/BLUDB\n",
"Done.\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" 1 | \n",
"
\n",
" \n",
" 3 | \n",
"
\n",
"
"
],
"text/plain": [
"[(Decimal('3'),)]"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql VALUES FLOOR(3.35)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 7. CEIL"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * ibm_db_sa://lzv55210:***@dashdb-txn-sbox-yp-dal09-12.services.dal.bluemix.net:50000/BLUDB\n",
"Done.\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" 1 | \n",
"
\n",
" \n",
" 4 | \n",
"
\n",
"
"
],
"text/plain": [
"[(Decimal('4'),)]"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sql VALUES Ceiling(3.35)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Thanks for reading :)\n",
"Created by [Tarun Kamboj](https://www.linkedin.com/in/kambojtarun/)."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}