Problem with sql query

Hey guys
I have one table with number_ID, and second with orders and I want to display sum of orders by number_ID

one table:
Number_ID
1
2
3
4

second table:
Number_ID Orders
1 14
1 25
1 32
2 9
2 86
3 5
3 3
4 2
4 1
4 12
4 4
4 1

Can someone know how write sql query ?

hi @pjacob,

use the “GroupBy”-Node and configure Number_ID as “Group column” and under “Manual Aggregation” define Orders as column and “sum” as Aggregation.

That will give you the sum of Orders for each Number_ID.

greetz, Tommy

3 Likes

Hi there @pjacob,

sql query syntax depends on database so a bit tricky to answer and not really a KNIME question. If you were wondering which node to use in order to write custom sql query you can try DB Query Reader. Also what @tommy suggested should work but you need to use DB GroupBy node which also outputs sql query in DB Query tab.

Br,
Ivan

4 Likes

Hi @pjacob,

you normally can do it with following SQL syntax.

SELECT Number_ID, SUM(Orders)
from [second table]
GROUP BY Number_ID
ORDER BY Number_ID

This is a basic SQL funtionality and should work for all SQL Databases.

BR
Hermann

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.