Write a query to return one summary row from marketplace_orders. gift_wrap is text containing values that SQL recognises as Boolean true or false.
Return gift_orders as the number of true flags and plain_orders as the number of false flags. A NULL flag counts towards neither total.
Ordering: Return a single row; sorting is not required.
Returngift_ordersplain_orders· any row order
About this problem
You practise converting a text flag into a real boolean instead of pattern-matching the spellings people happened to use. The gift_wrap column holds yes, Y, true, YES and 0 across six rows, and you return how many orders are gift-wrapped and how many are not, leaving the unanswered row out of both. The skill is reaching for the type conversion rather than an IN list.
Every wrong answer here is a list that is almost long enough. = 'yes' catches one row, lower(gift_wrap) = 'yes' catches two, and IN ('yes','Y','true','1') catches three because nobody thought of YES. The second mistake is quieter and worth more in an interview. Counting the plain orders as “everything that isn’t gift-wrapped” gives 2 instead of 1, because it sweeps the NULL row in with the people who said no. An unanswered question is not a no.
Read the lesson: Data Types & CAST (P13) →