Responsive Ad Area

Share This Post

test

Sum, Group by and Null

I’m dipping my toes into SQL. I have the following table

+------+----+------+------+-------+
| Type | ID | QTY  | Rate | Name  |
+------+----+------+------+-------+
| B    |  1 | 1000 |   21 | Jack  |
| B    |  2 | 2000 |   12 | Kevin |
| B    |  1 | 3000 |   24 | Jack  |
| B    |  1 | 1000 |   23 | Jack  |
| B    |  3 |  200 |   13 | Mary  |
| B    |  2 | 3000 |   12 | Kevin |
| B    |  4 | 4000 |   44 | Chris |
| B    |  4 | 5000 |   43 | Chris |
| B    |  3 | 1000 |   26 | Mary  |
+------+----+------+------+-------+

I don’t know how I would leverage Sum and Group by to achieve the following result.

+------+----+------+------+-------+------------+
| Type | ID | QTY  | Rate | Name  | Sum of QTY |
+------+----+------+------+-------+------------+
| B    |  1 | 1000 |   21 | Jack  | 5000       |
| B    |  1 | 3000 |   24 | Jack  | Null       |
| B    |  1 | 1000 |   23 | Jack  | Null       |
| B    |  2 | 3000 |   12 | Kevin | 6000       |
| B    |  2 | 3000 |   12 | Kevin | Null       |
| B    |  3 |  200 |   13 | Mary  | 1200       |
| B    |  3 | 1000 |   26 | Mary  | Null       |
| B    |  4 | 4000 |   44 | Chris | 9000       |
| B    |  4 | 5000 |   43 | Chris | Null       |
+------+----+------+------+-------+------------+

Any help is appreciated!


Sum, Group by and Null
Sum, Group by and Null
test
{$excerpt:n}

Share This Post

Leave a Reply

Your email address will not be Publishedd. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Skip to toolbar