Skip to content
Advertisement

Tag: aggregate

How to update a column based on values of other columns

I have a tables as below I have to update var_start_date column with min(reporting_date) for each combination of id,code,sub_code and item_nbr only till variance field is zero. Row with variance = 0 should have null var_start_date. and next row after that should have next min(var_start_date.). FYI, variance is calculated as par_cnt-orc_cnt so my output should look like this – I

PostgreSQL, SELECT CASE COALESCE

I need to ‘name’ categories: mycat is a text column with possible values ‘0’ to ‘4’. That works OK, but I have some an error in my program which very rarely writes null (or ” as I can see in pgAdmin). In such cases I have to treat that ” the same as ‘0’. But I can’t get that! I

TeraData aggregate function

When I try to select couple of columns with count, I get the following error: Selected non-aggregate values must be part of the associated group My query is something like this. Answer If you’re after a count for each combination of COLUMN1 and COLUMN2: If you’re after a count of all records in the table:

MS SQL query to list count by status

I want to achieved the result below. I want to list all records having a status of “For Approval” together with this condition: For example for Username ‘Leo’ Then sum all the status having “For Approval” which is the checker is ‘Leo’ with the condition above Answer I think this is what you are after; if its not i have

How to use GROUP BY to concatenate strings in MySQL?

Basically the question is how to get from this: foo_id foo_name 1 A 1 B 2 C to this: foo_id foo_name 1 A B 2 C Answer https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html#function_group-concat From the link above, GROUP_CONCAT: This function returns a string result with the concatenated non-NULL values from a group. It returns NULL if there are no non-NULL values.

Advertisement