I have a table like this (which also has other details):
order_id coupon_name
1 XMAS20
2 XMAS20
3 NYE10
4 NYE10
5 XMAS20
I want an sql query that returns this(in express):
[{ coupon_name: XMAS20, uses: 3 }, { coupon_name: NYE10, uses: 2 }]
In sql:
coupon_name uses
XMAS20 3
NYE10 2
With GROUP BY
, you should get all the COUPON_NAME
present in your table
SELECT COUPON_NAME, COUNT(*) AS USES FROM TABLE1 GROUP BY COUPON_NAME;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments