Counting specific rows mysql + express

Cedric Hadjian

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 
Vash

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Mysql Query for counting rows with specific days difference

From Dev

Trouble counting rows with specific value - Doctrine, Symfony2, mysql

From Dev

counting duplicate rows in mysql

From Dev

Counting specific values in rows in CSV

From Dev

MySQL COUNT(*) not counting result rows

From Dev

What to count when counting all rows MySQL

From Dev

Counting/totaling rows in a create view statement, mysql

From Dev

What to count when counting all rows MySQL

From Dev

MYSQL counting rows until last different row

From Dev

SQLAlchemy counting all rows, I want specific rows

From Dev

SQLAlchemy counting all rows, I want specific rows

From Dev

MySQL Ignoring Specific Rows?

From Dev

Selecting specific MYSQL rows

From Dev

MySQL Ignoring Specific Rows?

From Dev

MySQL - Rows with specific string into Column

From Dev

MySQL Order by specific rows only

From Dev

MySQL Order by specific rows only

From Dev

MYSQL pivoting rows and limiting by rows of a specific column

From Dev

PHP counting MYSQL rows that contain the same value in one column

From Dev

MySQL- Counting rows VS Setting up a counter

From Dev

PHP counting MYSQL rows that contain the same value in one column

From Dev

MySQL - Counting results for different criteria in case of multiple rows output

From Dev

Is it possible to avoid the "AS" parameter when counting total rows of a mysql table? (php)

From Dev

mysql pivot table with concat AND pivot counting of selected rows

From Dev

COUNTING mysql table rows based on 2 conditions from another table

From Dev

Counting rows in mysql table through procedure and interface in c#

From Dev

Counting rows with esqueleto

From Dev

Counting and aggregating by two rows

From Dev

Counting Rows for Grouping and Paging

Related Related

  1. 1

    Mysql Query for counting rows with specific days difference

  2. 2

    Trouble counting rows with specific value - Doctrine, Symfony2, mysql

  3. 3

    counting duplicate rows in mysql

  4. 4

    Counting specific values in rows in CSV

  5. 5

    MySQL COUNT(*) not counting result rows

  6. 6

    What to count when counting all rows MySQL

  7. 7

    Counting/totaling rows in a create view statement, mysql

  8. 8

    What to count when counting all rows MySQL

  9. 9

    MYSQL counting rows until last different row

  10. 10

    SQLAlchemy counting all rows, I want specific rows

  11. 11

    SQLAlchemy counting all rows, I want specific rows

  12. 12

    MySQL Ignoring Specific Rows?

  13. 13

    Selecting specific MYSQL rows

  14. 14

    MySQL Ignoring Specific Rows?

  15. 15

    MySQL - Rows with specific string into Column

  16. 16

    MySQL Order by specific rows only

  17. 17

    MySQL Order by specific rows only

  18. 18

    MYSQL pivoting rows and limiting by rows of a specific column

  19. 19

    PHP counting MYSQL rows that contain the same value in one column

  20. 20

    MySQL- Counting rows VS Setting up a counter

  21. 21

    PHP counting MYSQL rows that contain the same value in one column

  22. 22

    MySQL - Counting results for different criteria in case of multiple rows output

  23. 23

    Is it possible to avoid the "AS" parameter when counting total rows of a mysql table? (php)

  24. 24

    mysql pivot table with concat AND pivot counting of selected rows

  25. 25

    COUNTING mysql table rows based on 2 conditions from another table

  26. 26

    Counting rows in mysql table through procedure and interface in c#

  27. 27

    Counting rows with esqueleto

  28. 28

    Counting and aggregating by two rows

  29. 29

    Counting Rows for Grouping and Paging

HotTag

Archive