1
BundleID | ProductID| OrderNum
--------------------------------
1        | 1        | 1
1        | 2        | 2
2        | 1        | 1
2        | 2        | 2

Query Code :

SELECT COUNT(*) FROM table WHERE table.bundle_id = 2;

What I would like to do here is to add a new record (BundleID, ProductID, OrderNum), Where both BundleID & ProductID are pre-determined while the OrderNum will be the count + 1 (This is a music play list and I'm wondering if this is the best way to do it).

I've tried to figure out functions in postgres but I've got no progress with it.

Are they any tutorial which is easy to understad?

0

1 Answer 1

1

I chose 2 as given BindleID and ProductID

insert into your_table (BundleID, ProductID, OrderNum)
SELECT BundleID , ProductID , max(OrderNum) + 1 
from your_table 
where BundleID = 2 
and ProductID = 2
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.