mysql-error-1111

SQL Group By with an Order By

大城市里の小女人 提交于 2019-11-26 21:33:51
I have a table of tags and want to get the highest count tags from the list. Sample data looks like this id (1) tag ('night') id (2) tag ('awesome') id (3) tag ('night') using SELECT COUNT(*), `Tag` from `images-tags` GROUP BY `Tag` gets me back the data I'm looking for perfectly. However, I would like to organize it, so that the highest tag counts are first, and limit it to only send me the first 20 or so. I tried this... SELECT COUNT(id), `Tag` from `images-tags` GROUP BY `Tag` ORDER BY COUNT(id) DESC LIMIT 20 and I keep getting an "Invalid use of group function - ErrNr 1111" What am I doing

MySQL: Invalid use of group function

我的未来我决定 提交于 2019-11-26 11:20:39
I am using MySQL. Here is my schema: Suppliers( sid: integer , sname: string, address string) Parts( pid: integer , pname: string, color: string) Catalog( sid: integer, pid: integer , cost: real) (primary keys are bolded) I am trying to write a query to select all parts that are made by at least two suppliers: -- Find the pids of parts supplied by at least two different suppliers. SELECT c1.pid -- select the pid FROM Catalog AS c1 -- from the Catalog table WHERE c1.pid IN ( -- where that pid is in the set: SELECT c2.pid -- of pids FROM Catalog AS c2 -- from catalog WHERE c2.pid = c1.pid AND

MySQL: Invalid use of group function

喜欢而已 提交于 2019-11-26 02:20:10
问题 I am using MySQL. Here is my schema: Suppliers( sid: integer , sname: string, address string) Parts( pid: integer , pname: string, color: string) Catalog( sid: integer, pid: integer , cost: real) (primary keys are bolded) I am trying to write a query to select all parts that are made by at least two suppliers: -- Find the pids of parts supplied by at least two different suppliers. SELECT c1.pid -- select the pid FROM Catalog AS c1 -- from the Catalog table WHERE c1.pid IN ( -- where that pid