How to write a query with subquery in SQL?

Given a table tov_group , which spelled out the group of goods and their id, also given in table tovar, where the prescribed product id id_group (group id of product), name(product name), ed_izm (units of goods) and cost(cost of goods). You need to write a query that will print the list of units specifying the number of different groups that have goods, measured in appropriate units.

To avoid any suspicions that I wasn't even thinking, I bring out. code. The thing I wrote below does not work correctly. Help to fix it.
SELECT ED_IZM, (SELECT COUNT(ED_IZM) FROM TOVAR) FROM TOVAR GROUP BY ED_IZM
July 8th 19 at 16:29
4 answers
July 8th 19 at 16:31
Table:
--
-- The structure of the table `products`
--

CREATE TABLE IF NOT EXISTS `products` (
 `id` int(11) NOT NULL,
 `id_group` smallint(6) NOT NULL,
 `unit` varchar(20) NOT NULL
) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;

--
-- Data dump of table `products`
--

INSERT INTO `products` (`id`, `id_group`, `unit`) VALUES
(1, 1, 'meters'),
(2, 2, 'liters'),
(3, 1, 'kilograms'),
(4, 1, 'meters'),
(5, 1, 'liter'),
(6, 2, 'kilograms'),
(7, 1, 'kilograms');

--
-- Indexes stored tables
--

--
-- Indexes on the table `products`
--
ALTER TABLE `products`
 ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for saved tables
--

--
-- AUTO_INCREMENT for table `products`
--
ALTER TABLE `products`
 MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=8;

Request without joynow:
SELECT `unit`, COUNT(DISTINCT `id_group`) 
FROM `products` 
GROUP BY `unit`
July 8th 19 at 16:33
So sgoing and count ajtishniki products
What? - selmer_Hermann97 commented on July 8th 19 at 16:36
July 8th 19 at 16:35
Solution:
1 - the Right to go to your teacher for advice/additional occupation
2 - Wrong, but also working - to Pay the money to a friend/acquaintance/fellow student/freelancer for the decision
And then You say JOIN, and You do not know this word. And it seems to me that you should know.
You feel bad for rent. I am very well aware of and remembering all the material that we went through in class. DOP. we don't want to learn, because it is not the main subject of my profession. To pay I'm not going, because I will be able to do it yourself. - selmer_Hermann97 commented on July 8th 19 at 16:38
July 8th 19 at 16:37
in our time, the persistence was stronger, no one wrote on the forums how to solve the problem of permeable material
SELECT
COUNT(t1.ed_izm), t1.ed_izm 
FROM 
(SELECT DISTINCT t.ed_izm, t.id_group FROM tovar t) AS t1 
GROUP BY t1.ed_izm

The result:

1 kg
1 set
2 PCs

Just in case select * from tovar
1 Spoon 1 PCs 12,00
Fork 1 2 PCs 11,00
3 Plates 1 set of 400.00
4 1 Pots set of 500.00
5 1 Dummies a set of 300.00
6 Carrots 2 kg 10,00
7 Potatoes 2 kg 13,00
8 Beets 2 kg 17,00
Radish 9 2 kg 9,00
10 Lemon 2 PCs 5,00
11 Orange 2 PCs of 8.00

table product is
CREATE TABLE test.tovar (
 id int(11) NOT NULL AUTO_INCREMENT,
 id_group int(11) DEFAULT NULL,
 name varchar(50) DEFAULT NULL,
 ed_izm varchar(255) DEFAULT NULL,
 cost decimal(19, 2) DEFAULT NULL,
 PRIMARY KEY (id)
)
ENGINE = INNODB
AUTO_INCREMENT = 1
CHARACTER SET utf8
COLLATE utf8_general_ci
ROW_FORMAT = DYNAMIC;
I am glad that your time was the persistence harder, but you wrote me a elementary query that I could do and which in no way solves my problem. Carefully advise to read the conditions before commenting. - selmer_Hermann97 commented on July 8th 19 at 16:40
: TK corresponds to the result: you Need to write a query that will print the list of units specifying the number of different groups that have goods, measured in appropriate units. Or to Express himself more specifically, the telepath died 10 years ago. - selmer_Hermann97 commented on July 8th 19 at 16:43

Find more questions by tags SQLDelphi