Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
Is there a printf like function in mysql

This is a hackerRank THEPADS problem.

The question is query the number of ocurrences of each occupation in OCCUPATIONS. Sort the occurrences in ascending order, and output them in the following format:

There are a total of 2 doctors.

There are a total of 2 singers.

There are a total of 3 actors.

There are a total of 3 professors.

the occupations table goes like this

CREATE TABLE occupations(name varchar(100),Occupation varchar(100));

so how can i print this format is there any printf like function in mysql

Here is the image of the records present in occupations table: here is the image of the records present in occupations table

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can use concat method to append and group by and count function to get number for each occupation

SELECT "There are a total of ", count(OCCUPATION), concat(lower(occupation),"s.") FROM OCCUPATIONS GROUP BY OCCUPATION ORDER BY count(OCCUPATION), OCCUPATION ASC
over 4 years ago · Santiago Trujillo Report

0

Just to clarify. There is sucha function and it's SELECT. You can print things like this:

SELECT "Hello world" as "";

or

SELECT "Hello world" as ""\G;

There is no way to remove the : prefix in the second case.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!