sql server - How to sum two columns of different tables in sql -
i created 2 tables book , cd
**books** **book_id** **author** **publisher** **rate** angular2 132 venkat ts 1900 angular 160 venkat ts 1500 html 5 165 henry vk 1500 html 231 henry vk 2500 css 256 mark adobe 1600 java 352 john gulberg 4500 c# 450 henry adobe 1600 jsp 451 henry vk 2500 ext js 555 kv venkat w3 5102 html 560 kv venkat gulberg 5000 java2 561 john gulberg 9500 java8 651 henry vk 1650 js 654 henry ts 2500 java 777 babbage adobe 5200 phython 842 john ts 1500 spring 852 henry w3 6230 spring 895 mark tut 4250 ext js 965 henry gulberg 4500
book_id cd_name cd_price 132 angular2 500 132 angular1 600 132 angular basics 600 132 angular expert 900 160 begineer_course 1200 160 angular_templates 500 165 html_tutorials 900 165 bootstrap 1000 256 css styles 650 256 expert css 900 555 extjs 1200 555 exjs_applications 500 777 core java 2500 777 java swing 4500 777 java tutorials 1500 842 phython 650 852 spring 900 852 spring mvc 900
in above 2 tables want join books,author,cd_name , total cost of book , cd each id.
expected output
books book_id author cd_name total price angular2 132 venkat angular2 2400 angular2 132 venkat angular basics 2100 angular2 132 venkat angular expert 2800 java 777 babbage core java 7700
like above result need total cost books , cd
in case not books had cd:
select a.books , a.book_id , a.author , b.cd_name , a.rate+coalesce(b.cd_price,0) total_price book left join cd b on a.book_id = b.book_id
question's author evidenced "the table name book not books"
i used books "suggestion" because (usually) tables name plural.
Comments
Post a Comment