Get rows with Group BY in MySQL

NVO

Let's assume I have the following table:

example table

I need the numbers from the column 'Shares' ordered by 'Company'.

So, Example:

ABC, INC: 88624 + 5588 + 442214 + 11233

DEF Corp.: 4556 + 444863 + 44601

Is there a way to do this using MySQL? Or maybe PHP?

John

Aggregate function is the best method:

SELECT SUM(shares), company
FROM table_name
GROUP BY company

The SUM() will do the necessary calculation of the same company name. The GROUP BY will show them by company.

If you want specific companies not all (let's say 2 companies only): You can add WHERE Company = "ABC inc" OR "DEF Corp"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Get rows with Group BY in MySQL

From Dev

Get Rows By Group MySQL Java

From Dev

mysql query with GROUP BY not get all rows

From Dev

How to get the average and the last data from a group of rows in a table in MySQL

From Dev

how to get top 300 rows for each group in mysql?

From Dev

MySQL Limit Rows / Group By

From Dev

Creating view in mysql for a group of rows

From Dev

Temporarily Number Rows to Group by in MYSQL

From Dev

MySQL GROUP BY and remove null rows

From Dev

Group and display MYSQL rows by day?

From Dev

mysql group by return all the rows

From Dev

MySQL GROUP BY and remove null rows

From Dev

Grouping rows in mysql in clausule group by

From Dev

MySql Limit rows but without truncating group of rows

From Dev

Select rows with GROUP BY excluding GROUP with flag ( MySQL )

From Dev

get consecutive rows mysql

From Dev

MySQL query to get the max, min with GROUP BY and multiple table joins in separate rows

From Dev

MySQL - Get all rows from left table per group on right table

From Dev

MySQL Query: GROUP BY without loosing rows in result

From Dev

mysql select the first n rows per group

From Dev

Multiple group by and count the grouped rows using mysql

From Dev

MySQL group multiple rows based on DISTINCT value

From Dev

Mysql select min in group of rows where userid=?

From Dev

Selecting N rows from each group in MYSQL

From Dev

How to group rows in mysql to be as chunks with a specific size

From Dev

Mysql GROUP_CONCAT of first n rows

From Dev

MySQL GROUP BY: How to return multiple rows?

From Dev

MySQL sum last X rows per group

From Dev

MYSQL calculate time between rows and group as sessions

Related Related

HotTag

Archive