mysql-error-1111

#1111 - Invalid use of group function in mysql

我怕爱的太早我们不能终老 提交于 2021-01-27 20:56:16
问题 I have a table M_DAILY with fields PS_DATE date, tp int, ep int, mp int, and have a working version of a user defined function nvl(x,y) which returns x if not null and y if x is null My MySQL query is- select sum(avg(case date_format(PS_DATE,'%Y') when '2005' then nvl(tp,0) else 0 end))tp, sum(avg(case date_format(PS_DATE,'%Y') when '2005' then nvl(ep,0) else 0 end)) ep, sum(avg(case date_format(PS_DATE,'%Y') when '2005' then nvl(mp,0) else 0 end)) mp from M_DAILY where PS_DATE >= date ('2005

querying for user's ranking in one-to-many tables

不想你离开。 提交于 2019-12-24 19:22:55
问题 I am trying to write a query to find the score rank of a user's games. I need it to take in a user id and then return that user's relative ranking to other user's scores. There is a user and a game table. The game table has a userId field with a one-to-many relationship. Sample table: users: id freebee 1 10 2 13 games: userId score 1 15 1 20 2 10 1 15 passing $id 1 into this function should return the value 1, as user 1 currently has the highest score. Likewise, user 2 would return 2.

Update a column with a COUNT of other fields is SQL?

佐手、 提交于 2019-12-22 01:26:50
问题 Hi guys I have the following tables set up: Articles: ID | TITLE | CONTENT | USER | NUM_COMMENTS COMMENTS ID | ARTICLE_ID | TEXT I need a sql statement which updates the NUM_Comments field of the articles table with teh count of the comments made against the article like: update articles a, comments f set a.num_comments = COUNT(f.`id`) where f.article_id = a.id The sql above doesn't work and I get an Invalid Use fo Group function error. I'm using MySQL Here. 回答1: You can't have a join in an

SQL Query to Select Everything Except the Max Value

梦想的初衷 提交于 2019-12-21 12:44:27
问题 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:

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

家住魔仙堡 提交于 2019-12-17 19:36:15
问题 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

SQL Group By with an Order By

拜拜、爱过 提交于 2019-12-17 05:38:24
问题 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

Strange Mysql error 1111, supposedly worked before

一笑奈何 提交于 2019-12-12 03:39:39
问题 I am trying to troubleshoot a particular 'report' that gets generated on a PHP application running on a VOIP platform (billing related). The person that asked me to do this stated "it worked before" ;) MySQL Error thrown: 1111: Invalid use of group function Crazy thing is, it 'worked before' but stopped after awhile, they cannot place what event took place that might have created this bug. One thought is maybe MYSQL was upgraded? I googled the error, and can't seem to find a clear answer. At

INSERT… SELECT… WHERE… ON DUPLICATE… mysql query

自闭症网瘾萝莉.ら 提交于 2019-12-12 02:53:40
问题 Please help. I'm trying to update this one table with the current count of assets our products have. If the product already exist in the table, it should update the most updated count of the product. However, using the query below, mysql is returning me "ERROR 1111 (HY000): Invalid use of group function". I can't determine what's my error or if it is really valid to use count in function 'on duplicate key': INSERT INTO report_count_assets SELECT products.product_id, count(product_assets.asset

mysql use group by column in where condition

試著忘記壹切 提交于 2019-12-11 03:29:14
问题 How can I make this query work : SELECT column1.....,SUM(Hits) AS Hits FROM table WHERE SUM(Hits) > 100 GROUP BY column1..... The problem is the where clause, mysql display error : Error Code : 1111 Invalid use of group function I try to change the query to : SELECT column1.....,SUM(Hits) AS Hits FROM table WHERE Hits > 100 GROUP BY column1..... It did not help. thanks 回答1: SELECT column1.....,SUM(Hits) AS HitsSum FROM table GROUP BY column1..... HAVING HitsSum > 100 回答2: The reason for the

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

荒凉一梦 提交于 2019-12-06 04:44: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(