If you see the picture below, I only want to see those categories where the average revenue is greater than the overall average. The query that I’m using is below. The very last line is causing the issue. The error that I’m getting is: An aggregate may not appear in the WHERE clause unless it is i…
Tag: sql-server
Structure query builder generated SQL statement? Multiple joins to the same table?
Here’s the use case for this: Get me a list of heats where element #18 is between 95 and 100 AND element #2 is between 0.0 and 0.5. This works just fine (not sure it’s the best SQL/approach, but it works). The question/potential problem is that the number of element/range conditions is variable. T…
Break periods at the end of the month
SQL Server 2017 CREATE TABLE [TABLE_1] ( PLAN_NR decimal(28,6) NULL, START_DATE datetime NULL, ); INSERT INTO TABLE_1 (PLAN_NR, START_DATE) VALUES (1,’2020-05-01′), (2,’2020-08-01′); …
Column ‘Book.Title’ is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause
I’m creating a Library Management System and in the database I want to display book ISBN, Title and No. of copies of each book with their located library. Here’s the code I tried : It gives me the error Column ‘Book.Title’ is invalid in the select list because it is not contained in ei…
Is there a way to find out the overlap of two time ranges in SQL Server? [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 1 year ago. Improve this question I have four datetime2 columns, each representing either a start or an end to two different ti…
Search for an email in an nvarchar column in SQL Server
I am looking to search for a particular email (e.g., fname@exmaple.com) in an nvarchar column in SQL Server. It should have been as easy as – However the above query is not covering one case. If the result set contains a Comment like “Comment from a user with email selfname@example.com”. In …
SQL case sensitive compare
I like to know with a CASE statement wether two fields are the same. I managed to do it with following query but I wonder if there is a better approach? I just want the ‘=’ to do a case sensitive …
Pass Column Names into SQL statement in dynamic way – Python- SQL Server
Example of ‘fields’ value = name, surname, date I can put ‘fields’ in a list but I do not know how many (?) to put inside the query. Because, fields variable will include sometimes 5, sometimes 10 column names. I am trying to pass column names dynamically to the query. How can I solve …
SELECT from a table partition by order and status
So I have the following Searches table: The status is a combination of ClosedOn and ClosedByUserID: Pending: If ClosedOn and ClosedByUserId are null Outdated: If ClosedOn is not null and ClosedByUserID is null Closed: If ClosedOn is not null and ClosedBYUserID is not null I am trying to select all records and…
Problems passing a Python String to SQL query
I got some issues passing my SQL query made in Python to MS SQL. Were talking about retrieving some code via pyodbc, editing it with regex, and passing it back into a new table of the Database. I also tried some print()-Commands to assure the Code is running in Python and being edited the right way, but I am …