SQL vendor request
-
Hello. How to make a request "Determine the number of store suppliers from every country. The results are to be used by countries on alphabet.
Table:
CREATE TABLE postavschik ( id integer NOT NULL DEFAULT nextval('id'::regclass), nameofcompany character(40), country character(35), town character(30), zipcode character(10), address character(25), phone character(20), fax character(20), manager character(100), CONSTRAINT postavschik_pkey PRIMARY KEY (id) ) WITH ( OIDS=FALSE );
ALTER TABLE postavschik OWNER TO postgres;
Request
Select count(country) as "Количество", country as "Страна" from postavschik group by country;
Such a request finds a number from each country, but does not sort the alphabet. Used
order by country asc
Makes a mistake:"postavschik.country" column should appear in
proposal by the GROUP BY or used in the aggregate functionI don't understand. Help me, please.
DSB: PostgreSQL
-
Option 1: No SQL server. I checked for MS SQL, MySQL-- you can sort the field number, not entirely comfortable if additional fields are added in the request.
Select Count(country) as "Количество", Country as "Страна" From postavschik Group by country Order by 2;
Option 2: by means of
Select Kol as "Количество", country as "Страна" From ( Select count(country) kol, country as "Страна" From postavschik Group by country ) R Order by country;