0

I want to get group records of my mysql table. Here is database screenshot

enter image description here

I used this query

SELECT url, count(url) AS total_orders 
FROM orders 
GROUP BY url 
ORDER BY COUNT(url) DESC;

I got this result

enter image description here

But I also want to get store wise finance column data that have pending value.

Like

cmsapi.myshopify.com have 1 pending order in finance

b09a2a-2.myshopify.com have 1 pending order in finance

Actually I want to get result as below screenshot

enter image description here

How to get this all result in one mysql query ?

Regards

Hannah James
  • 540
  • 3
  • 14
  • 1
    You can group by multiple columns: `GROUP BY url, finance` – Barmar Jul 27 '23 at 06:01
  • Why are you unable to do this? – Barmar Jul 27 '23 at 06:02
  • If you only want to get pending value, use `WHERE finance = 'pending'`. The question isn't clear. – Barmar Jul 27 '23 at 06:02
  • @Barmar sir actually I want to get one extra column in final result having counts of each store that have finance "pending" only – Hannah James Jul 27 '23 at 06:03
  • If you want to get both the total count and pending count in one query, see https://stackoverflow.com/questions/33139000/multiple-query-same-table-but-in-different-columns-mysql/33139182#33139182 – Barmar Jul 27 '23 at 06:03
  • @Barmar here is the result I want sir: https://i.stack.imgur.com/5SNn6.png – Hannah James Jul 27 '23 at 06:08
  • Doesn't the question I linked to show how to do that? `SELECT url, COUNT(*) AS total_orders, SUM(finance = 'pending') AS finance_pending` – Barmar Jul 27 '23 at 06:09

0 Answers0