Summarizing by SQL query based columns

I saved a MySQL query.
Now I want to use that in another question, to aggregate some of the fields I have in SQL. None of the fields appear in "Sum" list. Why?

MySQL query is along the lines of this -

from xyz;

Hi @shrinath
Likely because none of those columns are numeric columns. Metabase requires numeric columns to use them in Sum etc.

Table has float fields. So query is just extracting those fields. Now when I use that query in question, it becomes non numeric?

Also, @flamber, if I am generating the question (query builder) directly on the table, these fields are showing up for summarization just fine. I am not able to use query builder because there's another json field I want to extract along with result. Hence the SQL query.

@shrinath I'm sure there's something you aren't posting in your example. Try casting explicitly then.

1 Like


Ok. So now my query looks like this -

  cast(payment_net as decimal(6,2)) as payment_net,
  cast(payment_tax as decimal(6,2)) as payment_tax
from xyz;

Now it works!

I dig deeper into why this is so, started looking at table in detail, I see these columns were set in varchar! #facepalm
I kept assuming this was numeric field looking at all numbers in there, my bad.
Sorry for wasting your time.

1 Like