A
A
Alexander2013-10-16 14:25:23
MySQL
Alexander, 2013-10-16 14:25:23

Query with counting values ​​from two columns (mysql)

in the product_id column, you need to count the number of duplicate values
​​in the notified column, you need to get the sum of all values ​​\u200b\u200brelated to your value in the product_id column

For example:
product_id = 19 there are 3 values
​​notified (for product_id = 19) sum = 2

As a result, I need to add the values ​​3 and 2 I 'm


trying this way
SELECT COUNT(*) + SUM(nwa.notified) FROM notify_when_arrives nwa GROUP BY nwa.product_id
but it doesn't turn out to be what I need ...

help me make a request

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
startsevdenis, 2013-10-16
@unix0

As far as I understand, this is how it should work.

SELECT nwa.product_id, (COUNT(*) + SUM(nwa.notified)) AS itog FROM notify_when_arrives nwa GROUP BY nwa.product_id

R
rozhik, 2013-10-16
@rozhik

SELECT product_id, COUNT(*) AS product_id_sum, SUM(nwa.notified) as notified FROM notify_when_arrives nwa GROUP BY nwa.product_id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question