A release of Matrix for some enthusiastic students

Hi people,
Greetings. I am trying to create a matrix of output for students who have decided to take music and/or Sports or not. I'm hoping to break down by age and sex and interest (Music/Sports).

Any help is greatly appreciated!

Thank you

Scripts to create the tables and INSERT records
create table student_tb(student_id varchar2(4), birth_date date, gender varchar2(1));
create table sports_tb (student_id varchar2(4));
create table music_tb  (student_id varchar2(4));

-- INSERTing into STUDENT_TB
insert into student_tb (student_id,birth_date,gender) values ('1001',to_date('01-JAN-90','DD-MON-RR'),'M');
insert into student_tb (student_id,birth_date,gender) values ('1002',to_date('10-JUL-91','DD-MON-RR'),'M');
insert into student_tb (student_id,birth_date,gender) values ('1003',to_date('01-DEC-90','DD-MON-RR'),'M');
insert into student_tb (student_id,birth_date,gender) values ('1004',to_date('10-AUG-92','DD-MON-RR'),'F');
insert into student_tb (student_id,birth_date,gender) values ('1005',to_date('01-JAN-91','DD-MON-RR'),'F');
insert into student_tb (student_id,birth_date,gender) values ('1006',to_date('01-FEB-91','DD-MON-RR'),'F');
insert into student_tb (student_id,birth_date,gender) values ('1007',to_date('01-AUG-90','DD-MON-RR'),'M');
insert into student_tb (student_id,birth_date,gender) values ('1008',to_date('01-SEP-90','DD-MON-RR'),'F');
insert into student_tb (student_id,birth_date,gender) values ('1009',to_date('01-OCT-90','DD-MON-RR'),'F');
insert into student_tb (student_id,birth_date,gender) values ('1010',to_date('10-MAR-89','DD-MON-RR'),'F');

-- INSERTing into SPORTS_TB
insert into sports_tb (student_id) values ('1001');
insert into sports_tb (student_id) values ('1004');
insert into sports_tb (student_id) values ('1005');
insert into sports_tb (student_id) values ('1009');
insert into sports_tb (student_id) values ('1010');


-- INSERTing into MUSIC_TB
insert into music_tb (student_id) values ('1001');
insert into music_tb (student_id) values ('1003');
insert into music_tb (student_id) values ('1010');
I hope to have a release in this way
Please note that I have no intention on adding males and females on a row by row basis. That's because it's the same student that would be involved in each category (MUSIC/SPORTS)
--------- MUSIC -------------------- SPORTS -----------
     Females      Males         Females        Males
Age            
20    0             0              1             0
21    0             0              0             0
22    0             1              2             0
23    0             1              0             1
24    1             0              1             0
My query - problem: I clear all data here, but I lost the information where how many girls or boys take Sports, music or nor
select age,
       sum(female) female_count,
       sum(male)   male_count,
       count(music_student_id) music_count,
       count(sport_student_id) sports_count
from
(
  select age, male, female, students.student_id student_id, music.student_id music_student_id, sports.student_id sport_student_id
  from
  (
    select student_id, trunc(months_between(sysdate, birth_date)/12) age,
           (
             case gender
               when 'F' then 1
               else 0
             end
           ) female,
           (
             case gender
               when 'M' then 1
               else 0
             end
           ) male
    from   student_tb
  ) students,
  (
    select student_id from music_tb
  ) music,
  (
    select student_id from sports_tb
  ) sports
  where students.student_id = music.student_id(+)
  and   students.student_id = sports.student_id(+)
)
group by age
order by age;
SQL> select age,
  2            sum(case when gender='F' and mid is not null then 1 else 0 end) music_females,
  3            sum(case when gender='M' and mid is not null then 1 else 0 end) music_males,
  4            sum(case when gender='F' and sid is not null then 1 else 0 end) sport_females,
  5            sum(case when gender='M' and sid is not null then 1 else 0 end) sport_males
  6  from (
  7  select trunc(months_between(sysdate, a.birth_date)/12) age, a.gender, s.student_id sid, m.student_id mid
  8       from student_tb a, sports_tb s, music_tb m
  9       where a.student_id = s.student_id (+)
 10            and a.student_id = m.student_id (+)
 11  ) group by age
 12  order by age;

       AGE MUSIC_FEMALES MUSIC_MALES SPORT_FEMALES SPORT_MALES
---------- ------------- ----------- ------------- -----------
        20             0           0             1           0
        21             0           0             0           0
        22             0           1             2           0
        23             0           1             0           1
        24             1           0             1           0

Tags: Database

Similar Questions

  • Adobe® Captivate® 8 HTML 5 release - no audio for some?

    Here's the story: I have a HTML 5 Captivate 8 course published that works in Chrome 44.0.2403.125 m, IE 11, local on my machine and through our Amazon S3 server. My colleagues in Geneva and France, however, see and hear the course on our test server (UST) but only see on our Production Server and do not hear it. Argh. These colleagues use IE9. Chrome works very well for them. Has anyone identified with a fix for this problem? Our client will have to distribute it widely so upgrading to IE11 or will Chrome is not an option. How can they see it in our test environment, but not the live environment?

    Why HTML5 only if you have a lot of people who could look at your content with old systems and browsers that are not mobile?

    I might suggest to your customer that they need to have an HTM/SWF version of the course available for people.

  • I bought my new laptop exactly a month before Windows 7 was released and standard for all new laptops. Am I entitled to upgrade to Windows 7 for free or at least some discount? __

    I bought my new laptop exactly a month before Windows 7 was released and standard for all new laptops. Can I upgrade to Windows 7 for free, or at least some discount?

    Thanks in advance,
    Donat

    Contact the manufacturer or ask in this forum instead: http://social.answers.microsoft.com/Forums/en-US/w7install/threads ~ Robear Dyer (PA Bear) ~ MS MVP (that is to say, mail, security, Windows & Update Services) since 2002 ~ WARNING: MS MVPs represent or work for Microsoft

  • I am a student and should have creative cloud as part of my tuition. I downloaded last year and everything worked fine. Now, for some reason, my licenses have expired.

    I am a student and should have creative cloud as part of my tuition. I downloaded last year and everything worked fine. Now, for some reason, my licenses have expired.

    Hello

    You will need to contact support by calling/chat for this request.

    Contact the customer service

    * Be sure to stay connected with your Adobe ID before accessing the link above *.

    Kind regards

    Sheena

  • toolbar moved for some reason my toolbar that was on the bottom of my office is now on the left hand side if, how do I return it to the bottom of the screen?

    for some reason my toolbar that was on the bottom of my office is now on the left hand side if, how do I return it to the bottom of the screen?

    Hello

    Are you referring to the taskbar on the desktop?

    Click on an empty space on the taskbar, and then hold down the mouse button, dragging the taskbar to one of the four sides of the office. Once the taskbar where you want, release the mouse button.

    For your reference:
    http://Windows.Microsoft.com/en-us/Windows-Vista/unlock-and-move-the-taskbar


    How to move the taskbar from its default position Windows or put it back to its default position
    http://support.Microsoft.com/kb/253679

    Kind regards
    Afzal Taher
    Microsoft technical support engineer

  • I have creative cloud but I can't find in the package lead Edge and I need it for some exercises, how do I get it, thanks

    I have creative cloud but I can't find in the package lead Edge and I need it for some exercises, how do I get it, thanks

    You can also download it via the direct link:

    Direct download links of Adobe CC 2015: 2015 creative cloud release | ProDesignTools

  • Sync slow/nonexistent for some shared folders in VMWare Fusion 6.0.2

    I have a mac host and a guest of Ubuntu linux. I recently upgraded from 6.0.1 to 6.0.2.

    The guest has the latest vmware tools installed (ie: Fusion 6.0.2).)

    I now have questions where the changes made to files on the host are not being detected by the guest operating system.

    Note: The shared folder on the host rose - I can still navigate the directories of the two systems... It's just that the changes to files on the host are not inside the guest.

    It is very problematic because my development environment is on OSX but my server on the linux client environment. Without a system of file sharing works I can't work, so all suggestions appreciated.

    Yes patches are in the 6.0.3 release.

    I think that the release notes for this issue only got mentioned in the workstation do not release the merge publication for some reason any.

    Thanks for the updates on the tests, as you did.

    Steve

  • New release of Edge for IE11 difficulty causing new problem

    I'm having a problem with mousenter and mouseleave. I think it has something to do with the opacity, but I'm not sure. Because of the IE 11 problem, I downloaded the latest version of adobe edge and re-released. When I downloaded the new files it solved the problem, and now I saw the edge files in IE 11. Now, I have a new problem. For some reason when I updated my files they stopped working properly.

    This is how the files look now.

    gas-drops3.jpg

    Here's how the file looked before the new update.

    gas-drops1.jpggas-drops2.jpg

    Now I looked in all sorts of reasons, it may not operate correctly and have found no solution. Has anyone else had problems. This effects all THE BROWSERS not only IE11.

    In fact, I solved the problem. For some reason when I did the update to resolve the problem of IE11 all grouped items use opacity on mouseleave stationary or mousenter were treated as a single element and would be broken. So I had to separate the elements and create each individual transition effect and it solved the problem. Not sure why this happened or if it was a bug, but it was the work around me.

    Thanks for reaching out and getting back to me.

  • How to get the phone and messages back in my dock apps? And for some reason, I discover now all my app pages from the middle of my phone and not at the top?

    How can I get the phone and messages apps in my dock? And for some reason, I discover now all my app pages from the middle of my phone and not at the top?

    Try

    Settings > general > reset > reset home screen presentation.

    Note: All other applications will be organised by alphabetical order.

  • Gmail and all the others crash in "Oops!" Google cannot load this page for some reason any

    I am running 10.10.5 and Firefox 41.0.2. Sophos said me no problem.

    In case of Gmail or any other program running in Firefox, the program stops to the message of the screen;
    "Oops!"

    "Google can not load this page for some reason any."

    The box Try Again has no effect.

    However the use of "Most visited" (top of the line LH of Firefox screen) returns to place that quit, without loss of data

    Clear the cache and delete cookies only from Web sites that cause problems.

    "Clear the Cache":

    • Firefox > Preferences > advanced > network > content caching Web: 'clear now '.

    'Delete Cookies' sites causing problems:

    • Firefox > Preferences > privacy > "Use the custom settings for history" > Cookies: "show the Cookies".

    If the deletion of cookies did not help, then it is possible that the cookies.sqlite file that stores the cookies has been corrupted.

    • Rename (or delete) cookies.sqlite (cookies.sqlite.old) and if present remove cookies.sqlite - shm and cookies.sqlite - wal in the Firefox profile folder in the cookies.sqlite case has been corrupted.

    You can use this button to go to the current Firefox profile folder:

  • I found that if it becomes necessary to use time machine to return to an earlier existence to reinstall the iphoto library, if for some reason, you lose lose, then when you try to synchronize your ipad is not recognized by the computer.  As one

    I found that if it becomes necessary to use time machine to return to an earlier existence to reinstall the iphoto library, if for some reason, you lose lose, then when you try to synchronize your ipad is not recognized by the computer.  So when you try to synchronize the pictures, they are all removed from the ipad and trying to reinstall everything again.

    This may or may not work immediately.  In my case, only half the photos have been installed, and then the error message came that the rest of 9000 can be installed.

    I contacted Apple support team who has made various suggestions.  Subsequently clicking on a photo list in iTunes were all going again and pictures of 9000 then installed.  When I asked the support team what could happen I was told that it was a "glitch".  I don't like seeds they mean that there could be an error in coding somewhere.

    Here me again.  I use an iMac and iPad.  I don't know why XP and iPhone came.

  • The numbers "could not open file for some reason any."

    Suddenly some of my documents of numbers prompt response "numbers" could not open file for some reason any ' "the document is unavailable. Other documents numbers remain accessible. My backup versions invites the same response when I try to open them. Is there a solution?

    Hello Fred,.

    Thanks for this info and choosing the communities Support from Apple. I know how important is able to open all your files in numbers is for you!

    If I understand correctly, you cannot open some files of numbers even from backups, but others continue to work. To limit this problem, I would suggest starting with the following steps:

    1. first of all, run disk utility and check for questions on your hard drive, as hard drive problems can lead to situations like yours.

    Disk utility (Yosemite): a disc repair

    2. then, you can test this in a new user, to refine, if it's a question broad system or specific to your username.

    How to test a question in another account on your Mac.

    See you soon!

  • Firefox 32.0.1 ignores min size of the font for some sites

    Firefox 32.0.1 ignores the setting of font size minimum for some sites.
    For example, http://vk.com or http://javaprogrammingforums.com

    At the top of the dialog box fonts, you will notice a selector 'fonts for"who can tell currently in Cyrillic. To match multiple pages on the web, set the minimum font even for 'Western' and 'Other languages' (pages Unicode covers the latter). -What helps with problem sites?

  • How can I see my recent/favorites contacts? I tried to go to settings to fix it, but for some reason that I don't have the option "show in app.

    I'm seeing my favorite/recent contacts on my phone. I know that you're supposed to go to settings / mail, contacts, calendar and go to the contacts section and click on view in the app, but for some reason button that I do not have this option. Someone knows why?

    Probably since iOS and iOS 9.3.x 9 there is no option, they show right here.

    Get help using iCloud Contacts, calendars, or reminders - Apple Support

  • Google Calendar becomes inactive in Firefox. Reset Firefox solves the problem for some time (sometimes minutes), then it becomes inactive.

    Google Calendar becomes inactive in Firefox. Can not navigate, cannot change the appointments, can only view an appointment, then freezes and nothing is more possible.
    Reset Firefox solves the problem for some time (sometimes minutes), then it becomes inactive.
    Firefox 28.0, Windows 7.
    Google Calendar is OK in Android and syncs with my PC OK.
    Works fine in Internet Explorer.
    Please notify.

    The extension Freeven pro is probably the problem. Only that disable and check again.

    If you have the same problem after having disabled the extension pro Freeven then, disable graphics hardware acceleration.

    You will have to perhaps restart Firefox for it to take effect, so save any work first (e.g. you compose mail, documents online that you are editing, etc.).

    Then perform the following steps:

    • Click on the orange top left Firefox button, then select the 'Options' button, or, if there is no Firefox button at the top, go to tools > Options.
    • In the Firefox options window, click the Advanced tab, and then select 'General '.
    • You will find in the list of parameters, the checkbox use hardware acceleration when available . Clear this check box.
    • Now restart Firefox and see if the problems persist.

    In addition, please check the updates for your graphics driver by following the steps in the following knowledge base articles:

    In safe mode hardware, acceleration is disable by default.

    Thank you.

Maybe you are looking for

  • Satellite C875-S7304 = problem with activation of Win8

    Yesterday I bought Toshiba Satellite C875-S7304 but I have the problem with the activation of windows 8 - 0xC004C003 error... Anyone has the same problem? How can I fix that?

  • 12.3.2.35 iTunes will not import audio CDs to win 10 Pro

    Just installed iTunes 64 bit 12.3.2.35 on a PC running Windows 10 Pro.  iTunes refuses to recognize that a CD is in the drive or provide options to import said tracks CD in iTunes. Running the diagnostics of iTunes for the CD/DVD drive, I get the fol

  • Photosmart HP 6520: MY HP Photosmart 6520 not print or copy in black

    I went on this forum and tried EVERYTHING. New cartridges (always use HP) cleaning printhead two online and with warm water and papertowels/qtips.  Re loaded drivers.  Nothing... and I don't even know why...

  • How can I tell if my computer is 64-bit processor

    Could someone tell me how to do what you please. I just bought a pc with dual core (woo! lol) (old technology for most ppl, but not for me!) and I need to see if I can load windows 7 64 bit on it

  • The user profile does not load correctly

    Running Vista Ultimate.  I have 2 user accounts, the two administrators.  If a user remains logged on for any period of time (more than 10 minutes), disconnects, and then another user logs on, they will get the dreaded "your user account is not load