mysql-error-1111

Error Code 1111. Invalid use of group function

女生的网名这么多〃 提交于 2019-12-05 11:19:37
问题 So this works: SELECT c.name AS country_name, c.population AS country_population, SUM(ci.population) AS city_population, ROUND(100*(SUM(ci.population)/c.population)) AS city_population_percent FROM country AS c JOIN city AS ci ON c.code = ci.countrycode WHERE c.continent = 'Europe' GROUP BY c.name But I need to only grab the city_population_percent values greater than 30, so I try this: SELECT c.name AS country_name, c.population AS country_population, SUM(ci.population) AS city_population,

CakePHP: How do I count the number of hasMany records in a find?

為{幸葍}努か 提交于 2019-12-04 11:15:18
I have two models, Post hasMany Comment . How do I select all Post that have less than two Comment ? I tried using a find with 'fields'=>array('COUNT(Comment.id) as numComments','Post.*') , (and then doing a numComments < 2 in 'conditions' ). But, I get a Unknown column 'Comment.id' in 'field list' error. Thanks! EDIT: I've gotten CakePHP to generate this query: SELECT `Post`.*, FROM `posts` AS `Post` LEFT JOIN comments AS `Comment` ON (`Post`.`id` = `Comment`.`text_request_id`) WHERE COUNT(`Comment`.`id`) < 2 GROUP BY `Comment`.`post_id` LIMIT 10 But I get an error #1111 - Invalid use of

SQL Query to Select Everything Except the Max Value

时光怂恿深爱的人放手 提交于 2019-12-04 05:42:06
I have this rather complex query that grabs data from three tables, and now I want it to be even more complicated (Oh dear)! I'd like the last posted feature to be displayed in it's own section of the page, and that's pretty easy by selecting the last entry in the table. However, for the complex query (the main page of the site), I'd like to be able to NOT have this feature displayed. I'd like to union the following query to my previous query, but it isn't returning the correct results: SELECT features.featureTitle AS title, features.featureSummary AS body, features.postedOn AS dummy, DATE

Error Code 1111. Invalid use of group function

冷暖自知 提交于 2019-12-03 23:03:39
So this works: SELECT c.name AS country_name, c.population AS country_population, SUM(ci.population) AS city_population, ROUND(100*(SUM(ci.population)/c.population)) AS city_population_percent FROM country AS c JOIN city AS ci ON c.code = ci.countrycode WHERE c.continent = 'Europe' GROUP BY c.name But I need to only grab the city_population_percent values greater than 30, so I try this: SELECT c.name AS country_name, c.population AS country_population, SUM(ci.population) AS city_population, ROUND(100*(SUM(ci.population)/c.population)) AS city_population_percent FROM country AS c JOIN city AS

MySQL INSERT INTO / ON DUPLICATE KEY with SELECT statement issue

谁都会走 提交于 2019-12-02 08:10:40
问题 Howdy - I'm a MySQL Noob. I have a table of various business listings and I am trying to populate a second table called cities that contains unique city names along with a count of how many listings per city. I'm able to do a SELECT statement that gets me this data fine like so: SELECT city,state,sum(count) FROM ( SELECT city,state, 1 AS count FROM listings ) results GROUP BY city ORDER BY sum(count) DESC,city; However, now I want to update the table, but I can't seem to get a proper

MySQL INSERT INTO / ON DUPLICATE KEY with SELECT statement issue

♀尐吖头ヾ 提交于 2019-12-02 03:48:24
Howdy - I'm a MySQL Noob. I have a table of various business listings and I am trying to populate a second table called cities that contains unique city names along with a count of how many listings per city. I'm able to do a SELECT statement that gets me this data fine like so: SELECT city,state,sum(count) FROM ( SELECT city,state, 1 AS count FROM listings ) results GROUP BY city ORDER BY sum(count) DESC,city; However, now I want to update the table, but I can't seem to get a proper statement to work. This is the latest that I have, but I'm currently getting a "Invalid use of group function"

ActiveRecord syntax for finding all items with an average rating of x or greater when using a join

拜拜、爱过 提交于 2019-12-01 05:43:45
I have two models in my rails application. Items and Reviews. Reviews belong to Item and Items has many Reviews. The review model looks like this: create_table "reviews", :force => true do |t| t.text "comment" t.integer "rating" t.integer "reviewable_id" t.string "reviewable_type" t.datetime "created_at" t.datetime "updated_at" end (Reviews are polymorphic so that's why they have a reviewable_id and a reviewable_type) I'm trying to put together an ActiveRecord query that will allow me to select all Items that have an average rating of of say 80 or more. I've tried a number of different

ActiveRecord syntax for finding all items with an average rating of x or greater when using a join

本秂侑毒 提交于 2019-12-01 02:43:48
问题 I have two models in my rails application. Items and Reviews. Reviews belong to Item and Items has many Reviews. The review model looks like this: create_table "reviews", :force => true do |t| t.text "comment" t.integer "rating" t.integer "reviewable_id" t.string "reviewable_type" t.datetime "created_at" t.datetime "updated_at" end (Reviews are polymorphic so that's why they have a reviewable_id and a reviewable_type) I'm trying to put together an ActiveRecord query that will allow me to

mysql query to update field to max(field) + 1

我们两清 提交于 2019-11-28 09:57:44
What I want to do is: UPDATE table SET field = MAX(field) + 1 WHERE id IN (1, 3, 5, 6, 8); The semantics of this statement, in my mind, would be first the database would go off and determine for me what the largest value of field is in all of table . It would then add 1 to that value, and assign the resulting value to the field column of the rows with id 1, 3, 5, 6, and 8. Seems simple enough... When I try to run that query though, MySQL chokes on it and says: ERROR 1111 (HY000): Invalid use of group function What's the secret sauce you have to use to get the outcome I desire? Regards, Vic GWW

#1111 - Invalid use of group function

半腔热情 提交于 2019-11-27 07:04:48
问题 I am using the following query in an attempt to get total number(sum) of slides retrieving the max number from each project, however I am receiving the following error (#1111 - Invalid use of group function). Here's the query: SELECT COALESCE(project,'Total') as Project, SUM(MAX(slides)) as Slides FROM projects_tbl WHERE date BETWEEN '2010-01-01' AND '2010-12-31' GROUP BY Project with ROLLUP If I remove the SUM(), then the it works, however, I do not get an accurate total for all of the