在表中获取相同的行

Ok i have table with this structure:

order_id product_id price

18645 289 5.90

18644 219 1.80

18644 109 2.30

18643 289 4.50

18642 180 9.80

18642 190 3.40

How i'm able to count same product_id's from a range of order_id's along with their according total prices per group of product_ids ?

to get the product wise COUNT and SUM you need to use aggregate functions GROUP BY product_id:

SELECT product_id,
       COUNT(1) AS product_count,
       SUM(price) AS total_price
FROM table_name
WHERE order_id BETWEEN 18642  AND 18645
GROUP BY product_id
ORDER BY product_count ASC, total_price ASC 

try this:

You need to just group by product_id

select product_id,
       count(*) as count ,
       sum(price) as price
from   <table>
where  order_id beteen <val1> and <val2>
group by product_id

Try

SELECT PRODUCT_ID,
       COUNT(product_id) totalCount,
       SUM(price) totalPrice
FROM tableName
WHERE Order_ID BETWEEN 00001  AND 99999
GROUP BY PRODUCT_ID