Mysql query

in mysql, how do you count non-blank cells in one line? And I want to count cells only between certain columns, say between columns 3-10. not all columns ... again, only in this row.

+1


a source to share


2 answers


Columns can only be handled in sql with names and not numbers, if you want to do this you will need to do it in the programming language that invokes the query



+1


a source


In theory relvar attributes are unordered and therefore you shouldn't be doing this. However, in MySQL, I believe you can query the directory to get the names as well as the "order" of the table columns. You can get the column names and order like so:

select column_name, ordinal_position from information_schema.columns where table_name='my_table'; 

      



However, I doubt this will help you too much. What you are doing smells like bad database design, and if you can't do anything with the design, which unfortunately happens sometimes, you can get rows from your table in a programming language for example. PHP and then use loops to "manually" count the nonblank cells in whatever cells you like. You can get strings in an array and then access individual cells by specifying the array index.

If you are happy to do this, then why not? It definitely shouldn't be too hard.

0


a source







All Articles