I have to make a query which will show used numbers and used times on few columns of integer type.
For this purpose I make a small example table with code suitable to paste into pgAdmin's sql editor:
DROP TABLE IF EXISTS mynums;
CREATE TABLE mynums
(rowindex serial primary key, mydate timestamp, num1 integer, num2 integer, num3 integer);
INSERT INTO mynums (rowindex, mydate, num1, num2, num3)
VALUES (1, '2015-03-09 07:12:45', 1, 2, 3),
(2, '2015-03-09 07:17:12', 4, 5, 2),
(3, '2015-03-09 07:22:43', 1, 2, 4),
(4, '2015-03-09 07:25:15', 3, 4, 5),
(5, '2015-03-09 07:41:46', 2, 5, 4),
(6, '2015-03-09 07:42:05', 1, 4, 5),
(7, '2015-03-09 07:45:16', 4, 1, 2),
(9, '2015-03-09 07:48:38', 5, 2, 3),
(10, '2015-03-09 08:15:44', 2, 3, 4);
Please help to build a query which would give results of used numbers and used times in columns num1, num2 and num3 together ordered by used times.
Result should be:
number times
2 7
4 7
1 4
3 4
5 5