sql - Return the maximum of all groups? -


Consider a simple table like the following table:

  create table example example_groups ( Id SERIAL primary key is not value1 INT, value is not 2 INT, not user_name text tap);   

with some lines in it:

  Example group_subjects (value1, value2, user_name) values ​​(3, 1, 'Tom'); Examples include example_groups (value1, value2, user_name) in values ​​(5, 2, 'tom'); Example in the example group (value 1, value2, user_name) value (1, 3, 'tom'); Example in the example group (value 1, value2, user_name) value (40, 10, 'john'); Example - include in groups (value 1, value2, username_name) (1, 11, 'John');   

I have the following query for the group in the table by SELECT SUM (value1), user_name column: Value 2), maximum (value 2) example_groups GROUP by user_name;

Return of the result I'm going to put it in another table (the query is INSERT SELECT )

I get my code named I want to return to the maximum value of all the rows in the MAX column. So far, I am doing this with a returning statement, although when I try to use it, I get an error.

What is the correct way to use Returning statement in this scenario?

Example of an unsuccessful query:

  SEUP SUM (value1), SUM (value2), MAX (value2) AS max2, GROUP from the example_groups returning (MAX (max2)) User_name;   

Ps I'm using postgrads.

also sum1 as SELECT SUM (value1), SUM (value2) ) As sum1, max (value2) as maxValue2, example_groups GROUP BY user_name) * whistle * maximum * = (select max) Choose whistle (maxValue2)

With sum1, SUM (value2) sum1, MAX (value2) as the SELECT SUM (value1), as in max_value2 example_groups GROUP by user_name) max_Of_all whistle with

  Select Max (maxValue2) from   


Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -