Help with tricky sql-questions
Hello!I am struggling with some additional questions at a SQL-course with Oracle and I have 2 questions that I can't get right. I shall create 2 views from a table looking like this:
tbl_persons
-----------
p_id
fname
ename
street
city
zip
food
food is a char Y or null
The first question looks like this:
1) Create a view called pers_stat upon tbl_persons that lists HOW MANY that has wrote down address, email, and that they will have food. (Far from every one has done that). Call the colums PERSON_ATTRIBUT and PERSON_COUNT. The values in the first column shall be "Address", "Email", "Food". In the second column shall be listing the count of every row that has something filled in.
I guess that the result shall look something like this:
PERSON_ATTRIBUT PERSON_COUNT
Address 187
Email 65
Food 39
----------------------------------------------
The second question looks like this:
2) Create a view that lists the 2 or 3 last letters from the column email and that calculates the count of each extension. As last row count how many email-addresses there is totataly.
I guess that the result shall look something like this:
EXT CNT
se 10
dk 21
com 10
org 3
Total 44
My attempt so far is (BUT I CANT MANAGE TO INCLUDE THAT LAST ROW WITH THE total):
CREATE OR REPLACE VIEW extension_count
AS
SELECT SUBSTR( email, INSTR(email, '.', -1, 1)+1, LENGTH(email) ) AS EXT, count(*) AS CNT FROM personer
WHERE
email <> NULL
OR
email <> ' '
GROUP BY SUBSTR( email, INSTR(email, '.', -1, 1)+1, LENGTH(email) );
SELECT count(*) AS totalt FROM extension_count_part_1
WHERE
email <> NULL
OR
email <> ' ';
So if any one could help me out with this it would be great.
Best regards, and Happy New Year!
Fredrik