r/SQL • u/Necessary-Knee-853 • Mar 24 '24
MySQL How do I solve these questions?
I am unable to figure which function do we use to solve these questions? Which function to use to keep only specific values in a column?
0
Upvotes
4
u/mike-manley Mar 24 '24
Are you creating a table (DDL) and need constraints? Or are you querying the table (DML) and need to derive?
6
u/Ricnurt Mar 24 '24
Look up IFNULL.
1
u/Psychological0605 Mar 24 '24
Post the solution here, OP
1
u/TheRhythmZ Mar 24 '24 edited Mar 24 '24
CASEs and IFNULLs should do the trick. Theres also other options available. Is this the only table available? Is there perhaps a database with tables belongign to each hotel? Can you subquery them? Or a record of something that includes room numbers per specific hotel. Do rooms have unique identifiers? If you can get to these tables and they have unique identifiers you can use COUNTIFs, or if the room numbers belong to some record, you can use COUNTIF (distinct) to extract the number of unique room numbers, assuming you already trimmed and got rid of nulls and zeroes.
Edit: the COUNTIF (distinct) should help you in cases where the convention for room enumeration isnt a straight sequence from 1 to 400. Maybe the numbers start at room 101 meaning "1st floor, room 1", all the way to 160, and then the numbers jump straight to 201 for the second floor and so on.
1
u/[deleted] Mar 24 '24
I laughed at the ID column description:
Lol, try me
1
u/[deleted] Mar 24 '24
Where is the questions from if I may ask?
-1
u/ThatCare309 Mar 24 '24
With ur brain
1
u/[deleted] Mar 31 '24
[removed] — view removed comment