Is it possible to conditionally select columns in MySQL?

MySQL as count group by?

  • select count(1), domain_id as "row_count", "domain_id" from rtr_traffic_mo group by domain_id; I gave the above query in mysql but instead of two columns its showing 3 columns. I basically want count(1) to be represented as row_count and domain_id as domain_id. It would be of great help if you could tell me what 1 is for in count(1) and what is the significance of 'group by' here. What if I dont give that.

  • Answer:

    By using 'group by domain_id;' you are instructing to show each domain_id only once in the result set. and in the 'select' clause you may perform certain functions on the data in different fields of the records having same domain_id. If you want to get the number of occurrences of each domain_id. you may use following query. select count(domain_id) as row_count, domain_id from rtr_traffic_mo group by domain_id;

Anirudh agarwal at Yahoo! Answers Visit the source

Was this solution helpful to you?

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.