SlideShare a Scribd company logo
1 of 2
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íaAyuntamiento del Valle de Mena
 
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 kellermcelrmarie
 
Short film festival
Short film festivalShort film festival
Short film festivalgrade4biss
 
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 evaluacionAlexandra 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

Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 

Recently uploaded (20)

Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 

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 ..................................................................................................................................................................................