I have a table with multiple fields, among which are: num1 (INTEGER), name(STRING) and datatime(TIMESTAMP). I would like to get the sample with name, sum(num1) and count(num1) grouped by month. I'm trying to do this:
SELECT name, sum(num1), count(num1) from mytable group by to_char(datatime, 'YYYY-MM')
But it doesn't work. Help me, please, and sorry for my English:)
Sum
not sun
Group By
not grouped by
name
. .
SELECT name, sum(num1), count(num1)
FROM mytable
GROUP BY to_char(datatime, 'YYYY-MM'), name
Generally if you're going to group your data by yyyy-mm you would generally want to see that in the select... but maybe you have your reasons... otherwise how do you tell multiple values of name apart? What's in ()'s are not in your results so... which John is which?
John 123 23 (1990-01)
John 234 44 (1990-02)
John 323 22 (1990-03)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.