I am trying to make a query to see the total price a customer has to pay when their order is completed, but I am having issues with this error statement. How do I get the correct query? ERROR: argument of HAVING must be type boolean, not type money Tables involved and inserting some fake quick data: Some of the
Tag: group-by
SQL: select max(A), B but don’t want to group by or aggregate B
If I have a house with multiple rooms, but I want the color of the most recently created, I would say: But I get the error: Column ‘room.color’ is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. If I say max(room.color), then sure, it will give me the
how to sum two columns from different tables MySQL
I need to sum the data from two different columns located in different tables and grouped by session_id….. I need to sum the column of spent_points + price_points grouped by session_id this is the result i hope to get I have tried with this query but I have only managed to group the data but I have not been able
SQL Browser Crashing when running a Nested Query
I have a database with three tables: grocery nutrient grocery_nutrient (for many to many) Actually, the database is very big and I am facing the problems by running this query, the SQL browser crashes when I run, if I add LIMIT it works. and this is the query I have written for it. Answer You can simplify your query if
Postgres – Select days with FAILURE status only
I have table with multiple result per days for particular project_name (SUCCESS, FAILURE, ABORTED, UNSTABLE). I would like to select only days where only FAILURE status occurs – nothing else. There are some days with multiple status (after FAILURE it can be solved and get status with different time and set to SUCCESS). How can I select only days with
MySQL – Query and group in a single row
I have a set of data as below: EmployeeId Salary_Basic Salary_Transport Year E001 12000 3000 2018 E002 9000 2000 2018 E001 13000 3200 2019 E002 10000 2400 2019 E003 15000 5000 2019 What I want is below: EmployeeID NetSalary_Year2018 NetSalary_Year2019 E001 15000 16200 E002 11000 12400 E003 0 20000 Can anyone suggest the sql query on MySQL please? Thanks Answer
PHP MySQL loop through the rows and print date when the date changes
My messages table is like this: This is my query used for fetching messages: I want to use created_at timestamp field to group messages in such a way so that I can display date when the message transactions took place. For example: I therefore want to print a new header containing date each time the date changes. My current PHP
Exploding the group by cel in individual cases
I am trying to convert the following table (fictitious): Person year price Tom 2019 100 Klaas 2020 100 John 2019 120 John 2020 120 Klaas 2020 150 Klaas 2020 150 John 2020 150 into: Person year price price price Tom 2019 100 NaN NaN Klaas 2020 100 150 150 John 2019 120 NaN NaN John 2020 120 150 NaN In
How to group by fields which have specific value in SQL?
I have the following columns in my table (I’m using postgresql): parent, child, status. Each parent has 1 or 2 children. I want to select all parents whose first child has status x and second child has status y or in case there’s only 1 child than parent with child with status x. For example, a table with the following
Error when SQL Server grand total comes out on first row instead of at table end
The following query gets row and column totals. When I add ORDER BY, the column total appears in the first row instead of the bottom row. What could be your suggested solution? Answer you can use grouping which returns 1 if the column is part of aggregation and you can use it in your order by: