![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have a table having this structure: idrecord nation value What I have to get by a query is grouping records by nation, summing and counting the values, dividing negative by positive. Therefore: USA, sumOfPositiveValues, CountOfPositiveValues, sumOfNegativeValues, CountOfNegativeValues ITALY, sumOfPositiveValues, CountOfPositiveValues, sumOfNegativeValues, CountOfNegativeValues FRANCE, sumOfPositiveValues, CountOfPositiveValues, sumOfNegativeValues, CountOfNegativeValues I hope I was clear enough :-) Thanks. Luciano |
#3
| |||
| |||
|
|
SELECT Nation, SUM(CASE WHEN Value >= 0 THEN Value END), COUNT(CASE WHEN Value >= 0 THEN Value END), SUM(CASE WHEN Value < 0 THEN Value END), COUNT(CASE WHEN Value < 0 THEN Value END)0 FROM YourTable GROUP BY Nation; |
![]() |
| Thread Tools | |
| Display Modes | |
| |