I am trying to get the top 5 products using a Mysql Query but it's giving me an error

xeyon
SELECT producttb.ProductName, producttb.ProductID, sum(ordertb.Qty) as Q from ordertb INNER JOIN producttb  on ordertb.ProductID = producttb.ProductID where ordertb.OrderDate between '2022-11-30' and '2023-01-18' group by producttb.ProductName order by Q desc LIMIT 5;

I am trying to get the top 5 products with the query above, but it's giving me an error.

Error Code: 1055. Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'ims.producttb.ProductID' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

S_IROTH

use ANY_VALUE() in the select for the fieldname not used in the group by statement

SELECT producttb.ProductName, ANY_VALUE(producttb.ProductID), sum(ordertb.Qty) as Q
from ordertb
    INNER JOIN producttb
    on ordertb.ProductID = producttb.ProductID
where ordertb.OrderDate between '2022-11-30' and '2023-01-18'
group by producttb.ProductName
order by Q desc LIMIT 5;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

I am trying to run a task in my async method but it's giving me a ui thread error

I am trying to build my game in unity but it is giving me an error

I am trying to make a SQL query of Update in python but it is giving error

I am trying to publish the App into playstores but its giving me for violating our dangerous products policy

My mysql query where I try to cast as integer is not working and giving me an error. What am I doing wrong?

I am trying to access attribute which I passed but it's giving me a null pointer exception

I am trying to fetch top rated 3 products

I am trying to use amazon api code in php but it is giving me error of not supported version following is my code

I am trying to use sharedPreferences from my Register Page and retrieve it on another class, but it is giving me error in the logcat

I am trying to update a value in an observable every second in setInterval but mobx is giving me error

i am trying to sort a vector of certain user defined data type but it is giving me syntax error c++

I am trying to call a function from useEffect hook and it's giving me undefined

I am trying to extract only date value from Oracle's SYSDATE but my query is giving me ORA-02290: check constraint violated

Why is this PHP / mySQL query giving me an error?

when i try to migrate my profile table its giving me the error .i am using laravel 5.1

i am trying to find region of interest and using cv2.polylines in the function but it is giving error?

Mysql get top products

I'm trying to use GLU.gluPerspective(), but it's giving me the static reference error

I am trying to use a bottom sheet modal in flutter conditionally only when users are not subscribed but it's giving me errors

I am getting error when I am trying to get video links of YouTube playlist using Paffy

I am trying to get rid of rows using multiple values, but I am getting an error

Pandas: The apply function I am using is giving me wrong results

I am using modulo operator, but it still giving me a negative number

I am trying to scrape Feature Image using scrapy in python but it's giving 'None' in fact I have attempted to 3 to 4 methods to Scrape

I am trying to import csv file into mysql, but I am getting below error. Can anyone help me?

I am using android studio 2.1.2 and am trying to get the latest facebook sdk, gradle seem to have an error

React When i am trying to get into a nested object the fetch throws me an undefined error

Get Top 5 Products in Each Category and Subcategory using Entity Framework

mysql query giving an error