Grouping the data after fetching the query

munish bansal

I have a problem while regrouping the data from query. I have a dataset like this:

PAT_ID MONTH  PRODUCT MOD SEV TOT_CNT
12341  201301 A       1   1   5
12342  201301 B       1   1   5
12343  201301 A       1   0   5
12344  201301 A       0   1   5

I am trying to select like in below query:

select month,product,sum(mod)/tot_cnt as mod_p,sum(sev)/tot_cnt as sev_p from table X group by month, product;

But Its giving output like:

MONTH  PRODUCT MOD_P SEV_P
201301 A       0.4   0.4
201301 A       0.4   0.4
201301 A       0.4   0.4
201301 A       0.4   0.4

I want only one row. i.e. 201301 A 0.4 0.4. I have specified group by clause, but it is not working

PeterRing

You need to distinct your elements like:

select DISTINCT month,product,sum(mod)/tot_cnt as mod_p,sum(sev)/tot_cnt as sev_p 
from table X 
group by month, product

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Fetching and grouping data by comparing time

From Dev

join query not fetching any data

From Dev

Nested query not fetching data correctly

From Dev

Fetching wrong data in query in rails

From Dev

sql query error data not fetching data proprerly

From Dev

PHP Oracle Query Data Grouping

From Dev

Fetching data only for specified mapping in HQL query

From Dev

SQL query for fetching data from multiple tables

From Dev

Fetching form data through query string in flask

From Dev

Mysql query is not fetching data as i want

From Dev

Error in database class in data fetching query

From Dev

Fetching data issue using simple like query

From Dev

Fetching data only for specified mapping in HQL query

From Dev

PHP / MySQL - Query not fetching any data

From Dev

Fetching data from MySQL, problems with diferent query

From Dev

Core data relationship nil after fetching

From Dev

notifyDataSetChanged() is not working after fetching data with Retrofit and DisposableSingleObserver

From Dev

model data is fetching after rending the view

From Dev

Handling state after fetching data - React

From Dev

update RecyclerView after fetching data from server

From Dev

Multiple select after grouping in Linq Query

From Dev

Get data by filtering and grouping LINQ query

From Dev

Grouping data in the same query with many joins

From Dev

Grouping and counting SQL query with Retrosheet baseball data

From Dev

Get data by filtering and grouping LINQ query

From Dev

SQL: Grouping data with sub-query

From Dev

Getting unspecified data while fetching data using mongoose find query

From Dev

custom function after grouping data.fame

From Dev

Rate of change Pandas Data Frame after grouping

Related Related

HotTag

Archive