0

I am using MS sql as a database. I want to write an nested query for that. My query is:

INSERT INTO [Node-churn](total_amount_in)  values=
       (SELECT sum(cast(amount as float)) 
        FROM [CDR-IN] 
        WHERE [Node-churn].subscriber=[CDR-IN].callee) 
WHERE degree <6

I got error for running this query. What would be the correct query for this problem?

P.S: Node-churn=(subscribers,degree), CDR-IN=(caller,callee,amount)

2 Answers 2

1

This is sort of what the select statement would be:

insert into [Node-churn](total_amount_in)
    select sum(cast(amount as float))
    from [CDR-IN]
    where [Node-churn].subscriber = [CDR-IN].callee and degree < 6;

But I think you want an update:

update [Node-churn]
    set total_amount_in = (select sum(cast(amount as float))
                           from [CRD-IN]
                           where [Node-churn].subscriber = [CDR-IN].callee
                          )
    where degree < 6;
Sign up to request clarification or add additional context in comments.

Comments

0

I'm not sure if you can use WHERE in an insert query. Maybe it's a typo, and the correct syntax is

INSERT INTO [Node-churn](total_amount_in)  values= 
   (SELECT sum(cast(amount as float)) 
    FROM [CDR-IN] 
    WHERE [Node-churn].subscriber=[CDR-IN].callee and degree <6
)

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.