Hi guys, I have two tables:
Categories: ID - Name - Desc
Elements ID - Name - CategoryID - Desc - Price
I need a query that returns a list of categories ranked by most occurrences in the element table
This should do the trick:
SELECT c.ID, c.Name, count(i.ID) FROM Categories c LEFT JOIN Items i on (c.ID=i.CategoryID) GROUP BY c.ID ORDER BY count(i.ID)
SELECT CategoryID, count(*) FROM items GROUP BY CategoryID ORDER BY 2 DESC
You can then join the categories to get their names.
Source: https://habr.com/ru/post/1730982/More articles:How to check already running exe in C # .net? - exeUpload / download files in ASP.NET - c #How to get processor load using Javascript or Java - javaHow to display the corresponding message (information or warning) in s: decorate? - javaConfused about JavaScript prototype inheritance - javascriptExpando Model in Django - google-app-engineWebservice-Client: используйте текстовый xml вместо иерархии объектов - javaJBoss ignores @RemoteBinding annotation - javajavascript tricks. Why (a, b, c) => 5 - javascriptCheck valid html C # - htmlAll Articles