SlideShare a Scribd company logo
First let me know, whether the output is like this,-

#Option :- 1

Initial Table:- (Table: 1)

               Roll                             Name                                           Gender                                       Age
XXXXXXX                                  XXXXXXX                                   F                                        XX
XXXXXXXX                                 XXXXXXX                                   M                                        XX


The Desired Result:- (Table: 2)

           Roll                       Name                                   Male                           Female                              Age
XXXXX                            XXXXXX                           NULL                             F                                 XX
XXXXX                            XXXXXX                           M                                NULL                              XX


The type of output that U want is converting the table into its “DENORMALISED” state, which is not
desired as U may face problem while writing other queries based upon the “Gender” criteria.

.................................................................................................................................................................

#Option:- 2

To check the Table from being Denormalised but at the same time the Gender column is sorted, i.e.
either U’ll get in Ur table first all the Female students details, and then the Male student details or
vice versa.

Example:

Table: 3

               Roll                             Name                                           Gender                                       Age
XXXXXXX                                  XXXXXXX                                                 F                          XX
XXXXXXXX                                 XXXXXXX                                                 M                          XX
                                                                                                 M
                                                                                                 F
                                                                                                 F


Table: 4

               Roll                             Name                                           Gender                                       Age
XXXXXXX                                  XXXXXXX                                                 F                          XX
XXXXXXXX                                 XXXXXXX                                                 F                          XX
                                                                                                 F
                                                                                                 M
                                                                                                 M


Then the SQL query for this desired output is,-
SELECT * FROM Table 1 where gender=’F’
UNION ALL
SELECT * FROM Table 1 where gender=’M’

.................................................................................................................................................................

#Option:- 3

From Table: 1 if U want to create a table containing details of students who are male then the SQL
query is,- ( I guess U know dis query)

Select *

From Table 1

Where gender=’M’

........................................................................................................................................................

#Option:- 4

Initial Table: (Table: 5)

student            gender           class         result
-------            ------           -----         ------
Bob                M                Math          A+
Mary               F                Math          A+
Peter              M                Math          A+
Jane               F                Math          B




Desired Output: (Table: 6)

males         females            class          result
-----         -------            -----          ------
2             1                  Math           A+
0             1                  Math           B


The code for this sort of result is,-

SELECT CLASS, RESULT,
SUM(CASE WHEN GENDER ='M' THEN 1 ELSE 0 END) MALE ,
SUM(CASE WHEN GENDER ='F' THEN 1 ELSE 0 END) FEMALE
FROM TABLE 5
GROUP BY CLASS,RESULT

..................................................................................................................................................................................

More Related Content

Viewers also liked

FUNERAIRE 2009, édition prometteuse
FUNERAIRE 2009, édition prometteuseFUNERAIRE 2009, édition prometteuse
FUNERAIRE 2009, édition prometteusewebcsnaf
 
Css image rollover
Css image rolloverCss image rollover
Css image rolloverManas Ranjan
 
El consistorio requiere a Orange desmantelamiento antenas telefonía
El consistorio requiere a Orange desmantelamiento antenas telefoníaEl consistorio requiere a Orange desmantelamiento antenas telefonía
El consistorio requiere a Orange desmantelamiento antenas telefonía
Ayuntamiento del Valle de Mena
 
Bar graph
Bar graphBar graph
Bar graph
juliebal
 
Rydygiera chrobrego jagiellonczyka_paulinskia
Rydygiera chrobrego jagiellonczyka_paulinskiaRydygiera chrobrego jagiellonczyka_paulinskia
Rydygiera chrobrego jagiellonczyka_paulinskiastalowy22
 
Week 22 keller
Week 22 kellerWeek 22 keller
Week 22 keller
mcelrmarie
 
Short film festival
Short film festivalShort film festival
Short film festival
grade4biss
 
Uso de las tecnologias en la evaluacion
Uso de las tecnologias en la evaluacionUso de las tecnologias en la evaluacion
Uso de las tecnologias en la evaluacion
Alexandra Quevedo
 
Presentation111111111111111111
Presentation111111111111111111Presentation111111111111111111
Presentation111111111111111111Rizwana Bano
 

Viewers also liked (12)

FUNERAIRE 2009, édition prometteuse
FUNERAIRE 2009, édition prometteuseFUNERAIRE 2009, édition prometteuse
FUNERAIRE 2009, édition prometteuse
 
Css image rollover
Css image rolloverCss image rollover
Css image rollover
 
ใบงาน 1
ใบงาน 1ใบงาน 1
ใบงาน 1
 
El consistorio requiere a Orange desmantelamiento antenas telefonía
El consistorio requiere a Orange desmantelamiento antenas telefoníaEl consistorio requiere a Orange desmantelamiento antenas telefonía
El consistorio requiere a Orange desmantelamiento antenas telefonía
 
Bar graph
Bar graphBar graph
Bar graph
 
Rydygiera chrobrego jagiellonczyka_paulinskia
Rydygiera chrobrego jagiellonczyka_paulinskiaRydygiera chrobrego jagiellonczyka_paulinskia
Rydygiera chrobrego jagiellonczyka_paulinskia
 
Mal de escuela
Mal de escuelaMal de escuela
Mal de escuela
 
Week 22 keller
Week 22 kellerWeek 22 keller
Week 22 keller
 
Short film festival
Short film festivalShort film festival
Short film festival
 
Uso de las tecnologias en la evaluacion
Uso de las tecnologias en la evaluacionUso de las tecnologias en la evaluacion
Uso de las tecnologias en la evaluacion
 
Presentation111111111111111111
Presentation111111111111111111Presentation111111111111111111
Presentation111111111111111111
 
Cap for managment nc1
Cap for managment nc1Cap for managment nc1
Cap for managment nc1
 

Recently uploaded

Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 

Recently uploaded (20)

Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 

Sql

  • 1. First let me know, whether the output is like this,- #Option :- 1 Initial Table:- (Table: 1) Roll Name Gender Age XXXXXXX XXXXXXX F XX XXXXXXXX XXXXXXX M XX The Desired Result:- (Table: 2) Roll Name Male Female Age XXXXX XXXXXX NULL F XX XXXXX XXXXXX M NULL XX The type of output that U want is converting the table into its “DENORMALISED” state, which is not desired as U may face problem while writing other queries based upon the “Gender” criteria. ................................................................................................................................................................. #Option:- 2 To check the Table from being Denormalised but at the same time the Gender column is sorted, i.e. either U’ll get in Ur table first all the Female students details, and then the Male student details or vice versa. Example: Table: 3 Roll Name Gender Age XXXXXXX XXXXXXX F XX XXXXXXXX XXXXXXX M XX M F F Table: 4 Roll Name Gender Age XXXXXXX XXXXXXX F XX XXXXXXXX XXXXXXX F XX F M M Then the SQL query for this desired output is,-
  • 2. SELECT * FROM Table 1 where gender=’F’ UNION ALL SELECT * FROM Table 1 where gender=’M’ ................................................................................................................................................................. #Option:- 3 From Table: 1 if U want to create a table containing details of students who are male then the SQL query is,- ( I guess U know dis query) Select * From Table 1 Where gender=’M’ ........................................................................................................................................................ #Option:- 4 Initial Table: (Table: 5) student gender class result ------- ------ ----- ------ Bob M Math A+ Mary F Math A+ Peter M Math A+ Jane F Math B Desired Output: (Table: 6) males females class result ----- ------- ----- ------ 2 1 Math A+ 0 1 Math B The code for this sort of result is,- SELECT CLASS, RESULT, SUM(CASE WHEN GENDER ='M' THEN 1 ELSE 0 END) MALE , SUM(CASE WHEN GENDER ='F' THEN 1 ELSE 0 END) FEMALE FROM TABLE 5 GROUP BY CLASS,RESULT ..................................................................................................................................................................................