【MySQL】hackerrank錯(cuò)題集

Print Prime Numbers

Write a query to print all prime numbers less than or equal to . Print your result on a single line, and use the ampersand () character as your separator (instead of a space).

For example, the output for all prime numbers would be:
2&3&5&7

Correct Answer

  select GROUP_CONCAT(n1 SEPARATOR '&') from (
      select n1 from (select n1, count(*) as factors from (
          select @a := @a+1 as n1 from information_schema.tables t1, information_schema.tables t2 limit 1000)   t1, 
          (select @b := @b+1 as n2 from information_schema.tables t1, information_schema.tables t2 limit 1000)   t2 
          where t1.n1%t2.n2 = 0 group by t1.n1) t 
      where factors = 2 order by n1)t3;
Draw The Triangle 1

P(R) represents a pattern drawn by Julia in R rows. The following pattern represents P(5):
* * * * *
* * * *
* * *
* *
*
Write a query to print the pattern P(20)

Correct Answer

  select repeat('* ', @number := @number - 1) from information_schema.tables;
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容