-1

I'm struggling to achieve this

VM  Disk    Capacity
VM1 Disk 1  100
VM1 Disk 2  40
VM1 Disk 1  100
VM1 Disk 2  40
VM2 Disk 1  45
VM2 Disk 1  45
VM3 Disk 1  30
VM3 Disk 2  30

The result should be like this

VM    Capacity
VM1    140
VM2    45
VM3    60
2
  • 3
    This is a simple question, but you need to show that you've attempted some sort of code. SO isn't a place for handouts. Feb 20, 2014 at 3:37
  • @user3330821 Can you check my answer
    – Nagaraj S
    Feb 20, 2014 at 4:11

3 Answers 3

0

Does this help?

SELECT a.column1, SUM(column3) FROM
(
SELECT DISTINCT column1, column2, column3 FROM tableA
) a 
GROUP BY column1
1
  • Sorry @ydoow, I accidentally edited your answer. Down vote for me. Feb 20, 2014 at 4:03
0

Here you go

http://sqlfiddle.com/#!6/285fe

SELECT a.vm, SUM(capacity)
FROM (
SELECT DISTINCT vm, DISK, capacity
FROM TEMP
) a
GROUP BY vm
0
SELECT a.vm, SUM(capacity) as capacity FROM
  (
SELECT DISTINCT vm, disk, capacity FROM test
  ) a 
GROUP BY vm

SQL fiddle

enter image description here

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.