-3

I have a database table in MySql as follows :

  myTable
      col1 integer
      col2 integer
      col3 text

There are many more columns in the table, but for my question, these three matter.

What I want to do is that, I want to print the sum of column 1 and column 2. With this, I want to print the string from col3 which has maximum occurrence. If there are more strings with the same occurrence, I want to print which comes first alphabetically. How is that possible in MySql ? Is it even possible in single query? (This can be marked as a homework question. I am trying to figure out the solution but with my current knowledge base I am not able to do it. Some pointers on how it can be solved or some hints will prove helpful.

Dominique
  • 1,080
  • 14
  • 29
user3686864
  • 337
  • 2
  • 5
  • 13

1 Answers1

1

Since you are asking for homework support, I'm not going to provide the query itself.

That said, you should look into GROUP BY Functions to calculate the number of occurrences for a word. In addition, look into ORDER BY to learn how to sort your results. Adding the value of different columns is a simple expression which you can just write in the SELECT statement.

andy
  • 2,002
  • 1
  • 12
  • 21