September 23, 2016 at 4:11 am
Hi I am new to this application and my question I believe is rather basic, so forgive me.
I have two tables A and B below and I wish to get the following
Order No Qty
1 6
2 8
Table A has order nos and other info
Order No
1
2
3
..
Table B has order no and quantity and other info
order qty
1 1
1 2
1 3
2 4
2 1
September 23, 2016 at 4:21 am
mike.jones 60369 (9/23/2016)
Hi I am new to this application and my question I believe is rather basic, so forgive me.I have two tables A and B below and I wish to get the following
Order No Qty
1 6
2 8
Table A has order nos and other info
Order No
1
2
3
..
Table B has order no and quantity and other info
order qty
1 1
1 2
1 3
2 4
2 1
Hi Mike,
rather than awnser your question directly, may I point you to a resource that will help answer this, and many others, that you will have while learning sql?
http://www.sqlservercentral.com/stairway/75773/
I'm a DBA.
I'm not paid to solve problems. I'm paid to prevent them.
September 23, 2016 at 10:21 am
mike.jones 60369 (9/23/2016)
Hi I am new to this application and my question I believe is rather basic, so forgive me.I have two tables A and B below and I wish to get the following
Order No Qty
1 6
2 8
Table A has order nos and other info
Order No
1
2
3
..
Table B has order no and quantity and other info
order qty
1 1
1 2
1 3
2 4
2 1
The data in your tables doesn't support the desired output... 4+1=5 not 8...
Also... Base on the sample data, the desired output does not require table A to be involved at all...
SELECT
b.Order
Qty = SUM(b.qty)
FROM
dbo.TableB b
GROUP BY
b.Order
ORDER BY
b.Order
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply