Q:

PostgreSQL: How to get a sum of values and the total rows that went into each value? 

I have a table, MyData in the following format:
|id|theme_id|priority_id|value|

I am trying to get the following result for all the rows:
theme_id | priority_id | total | sum
------------------------------------
    1    |      1      |   3   |  5
    1    |      2      |   5   |  12
    1    |      3      |   1   |  3
    2    |      1      |   2   |  6

The idea is group all the rows by theme_id and priority_id and then sum up the values for that grouping, as well as, to get the total rows that went into that sum. 
When I try the following, I get a total column that equals to the sum column:
WITH breakdown AS (
  SELECT id, theme_id, priority_id, value
  FROM MyData
)
SELECT theme_id, priority_id, sum(value) AS values, count(id) as total
FROM breakdown
GROUP BY theme_id, priority_id

I have also tried:
SELECT theme_id, priority_id, sum(value) AS values, count(id) as total
FROM MyData
GROUP BY theme_id, priority_id

Both of the above give me the same output:
theme_id | priority_id | total | sum
------------------------------------
    1    |      1      |   5   |  5
    1    |      2      |   12  |  12
    1    |      3      |   3   |  3
    2    |      1      |   6   |  6

A:

I have created the following sample DDL structure in order to work the necessary queries:
CREATE TABLE my_data
(
    my_data_id  SERIAL,
    theme_id    INT NOT NULL,
    priority_id INT NOT NULL,  
    my_value    INT NOT NULL,
    CONSTRAINT pk_my_data PRIMARY KEY (my_data_id)  
);

CREATE TABLE theme
(
    theme_id  SERIAL,
    name      CHAR(6) NOT NULL,
    CONSTRAINT pk_theme PRIMARY KEY (theme_id)  
);

CREATE TABLE priority
(
    priority_id  SERIAL,
    name         CHAR(6) NOT NULL,
    CONSTRAINT pk_priority PRIMARY KEY (priority_id)  
);

Then, inserted the following test data into the respective tables:
INSERT INTO theme (name)
VALUES ('first');
INSERT INTO theme (name)
VALUES ('second');
INSERT INTO theme (name)
VALUES ('third');

INSERT INTO priority (name)
VALUES ('high');
INSERT INTO priority (name)
VALUES ('medium');
INSERT INTO priority (name)
VALUES ('low');

INSERT INTO my_data (theme_id, priority_id, my_value)
VALUES (1, 1, 6);
INSERT INTO my_data (theme_id, priority_id, my_value)
VALUES (1, 2, 5);
INSERT INTO my_data (theme_id, priority_id, my_value)
VALUES (1, 3, 8);
INSERT INTO my_data (theme_id, priority_id, my_value)
VALUES (1, 1, 3);
INSERT INTO my_data (theme_id, priority_id, my_value)
VALUES (1, 2, 4);
INSERT INTO my_data (theme_id, priority_id, my_value)
VALUES (1, 3, 11);

INSERT INTO my_data (theme_id, priority_id, my_value)
VALUES (2, 1, 7);
INSERT INTO my_data (theme_id, priority_id, my_value)
VALUES (2, 2, 3);
INSERT INTO my_data (theme_id, priority_id, my_value)
VALUES (2, 3, 9);
INSERT INTO my_data (theme_id, priority_id, my_value)
VALUES (2, 1, 1);
INSERT INTO my_data (theme_id, priority_id, my_value)
VALUES (2, 2, 13);
INSERT INTO my_data (theme_id, priority_id, my_value)
VALUES (2, 3, 10);

INSERT INTO my_data (theme_id, priority_id, my_value)
VALUES (3, 1, 1);
INSERT INTO my_data (theme_id, priority_id, my_value)
VALUES (3, 2, 8);
INSERT INTO my_data (theme_id, priority_id, my_value)
VALUES (3, 3, 2);
INSERT INTO my_data (theme_id, priority_id, my_value)
VALUES (3, 1, 6);
INSERT INTO my_data (theme_id, priority_id, my_value)
VALUES (3, 2, 5);
INSERT INTO my_data (theme_id, priority_id, my_value)
VALUES (3, 3, 4);

And, finally the concrete SELECT statement with its corresponding aggregate functions that provide your desired result set:
SELECT theme_id, 
       priority_id, 
       SUM(my_value) AS values_sum, 
       COUNT(*)      AS total_rows
  FROM my_data
GROUP BY theme_id, priority_id 
ORDER BY theme_id ASC, priority_id ASC;

In this way, we can see that you almost had it with your second query but, as @a_horse_with_no_name has pointed out, you needed to replace count(id) with count(*), so that you could get your correct data.  I have also included the ORDER BY clause for sorting the columns. 
By means of this SQL Fiddle sample, you can confirm that the results yielded by SUM and COUNT are correct.  As you can see I've added theme and priority, which are relevant tables for this query, along with the required test data.