Leorah Sumarong
Leorah Sumarong

Reputation: 127

How to get this structure in mysql script

I have this table in my database see attached images

enter image description here

Now what i wanted is to count all the or_number and get the total sales_total with the same sales_date in different sales_branch Here is my sample script:

    SELECT *,sum(sales_total) as total,group_concat(DISTINCT or_number) as 
    orn FROM `tbl_sales` GROUP by sales_date

OUTPUT: enter image description here

Which is wrong because it doesn`t count the sales_total and the different sales_branch group into one because the of the sales_date.

Any idea please help.

Upvotes: 0

Views: 56

Answers (1)

Leorah Sumarong
Leorah Sumarong

Reputation: 127

Here is my sql script:

SELECT *,sales_date, sales_branch, COUNT(DISTINCT or_number), SUM(sales_total) AS total_sales FROM tbl_sales GROUP BY sales_date, sales_branch

Upvotes: 1

Related Questions