Question

Write an aggregate called selectivesum that sums the values of numbers in a column, but only...

Write an aggregate called selectivesum that sums the values of numbers in a column, but only if the value is present in the table t . E.g., suppose t contains the values 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. Suppose that table m has a column y of type integer. Here is the table M


Psuedocode for the sfunc function:The result of the query SELECT selectivesum(y) FROM m; is 7.

step(x, y)

if(y is in t)

return x + y

else

return x

Here is the code to create the table m:

drop table if exists m;

create table m (x text, y integer);

insert into m values (‘cat’, 4), (‘erpi’, 12), (‘llar’, 3);

Homework Answers

Answer #1

Given-

Table m :

consisting of the datatypes text and integer.

Table t:

contains numeric values

selectivesum() -> function which sums the values in a particular column only if they are present in the table .

Code-

CREATE OR REPLACE FUNCTION selectivesum(y)

RETURN number IS

total number(2) :=0;

BEGIN

IF y is in t THEN

total := total+y;

RETURN total;

END;

Explanation-

Function is created with the given parameter and then the function checks if the value of y ( integer ) which is in the table m and adds to the total variable which is initialized as zero in the beginning of the procedure, if it is present in another table t, which consists of only numerical values, and then the return statement is used to give the total computed.

  

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Question 1: Group by and Aggregates: Write SQL statements to answer the following questions using Assignment...
Question 1: Group by and Aggregates: Write SQL statements to answer the following questions using Assignment 4’s schema (Customer-Invoice-Line-Product-Vendor). Make sure that your SQL script runs without any errors. Submit your answers in a .SQL file. 1 (2 Points) - Find the count of distinctvendors thatsupplied products that are priced lowerthan 185? 2 (2 Points) - For each vendor, find their product that has the lowest product quantity. Your output should include vendor code, vendor name, product description and product...
Write an assembly program to compute the following expressions Create a list named ‘z’ of size...
Write an assembly program to compute the following expressions Create a list named ‘z’ of size 3 using DUP operator. Leave the list ‘z’ uninitialized. You can denote the items in the list as [z0, z1, z2]. z0 =x+13 z1 = y-x z2= r+z1-13 Where x, y, r are 16-bit integer memory variables. x = 7, y = 20, r = 4 Use the debugger to verify your answer. Please answer using this format for code: .386 .model flat, stdcall...
Using MySQL... Join the Students, Enrollment, and Classes table to display the UniqueCode and the students’...
Using MySQL... Join the Students, Enrollment, and Classes table to display the UniqueCode and the students’ classes (34 rows) Alter the Enrollment table to create column FullName Update the Enrollment table (using a subquery) to fill in the FullName selecting the students from the Student table (34 rows changed) Using Union (WHERE conditions limited to 1 condition each), display the students names whose HeightInches is greater than 65 or less than 72 (13 rows) Using “Intersection”, display the students names...
Using the Class database, answer the following questions: 1. Becca missed class on September 15, 2015....
Using the Class database, answer the following questions: 1. Becca missed class on September 15, 2015. Insert this absence into the absence table. Insert your snip of the construct used here. b. Display the contents of the absence table. Be sure all rows are displayed. CREATE DATABASE Class; #-- Using the database USE Class; # create student table DROP TABLE IF EXISTS student; CREATE TABLE student (    name VARCHAR(20) NOT NULL,    gender ENUM('F','M') NOT NULL,    student_id INT...
SQL DATABASE Task 4 [1.5 marks] Create Index (0.5 marks) Currently, the database only contains a...
SQL DATABASE Task 4 [1.5 marks] Create Index (0.5 marks) Currently, the database only contains a small number of records. However, the data contained within it is expected to grow significantly in the future. Creating indexes on commonly searched columns is a way performance issues can be minimized. Write a command to create an index on student_name column of the student table. Create view – 1 mark Write a command to create a view to list the student ID and...
Find the total number of employees and the total number of dependents for every department (the...
Find the total number of employees and the total number of dependents for every department (the number of dependents for a department is the sum of the number of dependents for each employee working for that department). Return the result as department name, total number of employees, and total number of dependents Based on the following table: -- drop tables DROP TABLE EMPLOYEE CASCADE CONSTRAINTS; DROP TABLE DEPARTMENT CASCADE CONSTRAINTS; DROP TABLE DEPT_LOCATIONS CASCADE CONSTRAINTS; DROP TABLE PROJECT CASCADE CONSTRAINTS;...
SQL Write the queries necessary to obtain the required information 1) Use sub query and “in”...
SQL Write the queries necessary to obtain the required information 1) Use sub query and “in” keyword to print the salesreps (ids) who have taken order for the companies ‘Zetacorp’ or ‘JCP Inc.’ . Duplicate rows are not allowed 2) Use sub query to find the id and the name of every sales rep that represents at least one customer with a credit limit of greater than $5000. 3) Use sub query and keyword “exists” to list the id and...
This is in java and you are not allowed to use Java API classes for queues,...
This is in java and you are not allowed to use Java API classes for queues, stacks, arrays, arraylists and linkedlists. You have to write your own implementations for them. You should construct a BST by inserting node values starting with a null tree. You can re-use the code for the insert method given in the sample code from the textbook. -insert method is provided below Your code should have a menu driven user interface at the command line with...
Create the ArrayList program example in listing 13.1, Battlepoint. Describe the code (in your WORD document)...
Create the ArrayList program example in listing 13.1, Battlepoint. Describe the code (in your WORD document) in the 'if' statement if (targets.indexOf(shot) > -1) { ADD a NEW ArrayList of points called 'misses' ADD code to add a point to the 'misses' list on a miss (if a SHOT does NOT hit a TARGET) ADD code to place an 'M' in the final output map for all shots that were MISSES. ADD code to place an H on the target...
In this lab, you will write a program that creates a binary search tree based on...
In this lab, you will write a program that creates a binary search tree based on user input. Then, the user will indicate what order to print the values in. **Please write in C code** Start with the bst.h and bst.c base code provided to you. You will need to modify the source and header file to complete this lab. bst.h: #ifndef BST_H #define BST_H typedef struct BSTNode { int value; struct BSTNode* left; struct BSTNode* right; } BSTNode; BSTNode*...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT