I want to use columns from three different tables and use them to calculate how much each customer has ever spent. tblCustomer(CustomerID) tblOrder(CustomerID, ProductID, Amount) tblProduct(ProductID, Price) So I want to filter out the orders made by a customer, check what product they ordered and what amount of it, check the price and multiply it with the amount they ordered
I need to get count of total count for the query I had in postgresql
I created a select query as following, now I need to get the total count of the “No.of Ideas generated” column in a separate row as total which will have a count of the individual count of particular idea_sector and idea_industry combination. Query: Output: Required output: Answer You can accomplish this with grouping sets. That’s where we tell postgres, in
Append additional conditions to a query
I have a query where I need to add several conditions as an OR clause, because I want to use LIKE, so I can not use IN instead. So how can I add multiple OR from an array? The SQL should look like this: where ‘a’, ‘b’, ‘c’ is from an array. Answer From the Rails API docs, the .or
Issue with adjusting CAST in a calculation (precision)
I believe it should be an easy fix for someone who is good at casting. I appreciate your help. My calculation is : Example Therefore my calculation is But I have 1.00 as a result There is an issue with precision I believe. Does someone know how I can adjust the so that the 4 is not dropped? Answer I
Date in where clause returning 0 rows
I am trying to get data as follows WHERE DateCommande = ‘2018-09-05’ but it doesn’t work on my computer. Returns rows, including rows that show 2018-09-05 as the datetime value in a datetime column. However, on SSMS on my computer, if I add a WHERE clause, the query returns 0 rows: Answer yyyy-mm-dd hh:mm:ss.000 is not a language- and regional
Is it possible you instatiate a variable in SQL server using a select statement with another variable
I am attempting to DECLARE a variable then SET it’s value using a secondary variable which has already had it’s value set. I have tried: To no avail. The result of the final SELECT statement is null. The following works: but I have several tables linked via dependencies and to delete an entry I need to traverse the tables in
How to solve syntax error with `ALTER TABLE` query?
I’m having issues with syntax error in my queries, I’m trying to alter my table. Answer Looking at your question I dind’t know what you were trying to rename if it was your table name or the column name. For SQL Server to rename your column you can do this: With your code should look like this: Otherwise if you’re
Best way to update the same column without using x update statements (if possible)?
I have a few questions regarding the following scenario – Consider this table (db<>fiddle here): I want to replace each class subject with a number code. For example: If I try to do this in one update statement, it won’t let me do that. The only thing I could think of was four separate statements using replace: This almost works,
Pivot/Unpivot SQL Result Set Column Names into Separate Column
I have a result set something like this: Username Birthday Gender Tom Jan 23 Male I would like to convert it to something like this: Name Value Username Tom Birthday Jan 23 Gender Male I’ve been told Pivot/Unpivot was what I was looking for, but I can’t find any info on pulling the column names. Is there a way to
Django ORM compare tuples / lexicographic ordering
As part of some custom cursor-based pagination code in Python Django, I would like to have the below filtering and ordering on a generic Queryset (where I don’t know the table name up front) How can this be expressed in terms of the Django ORM? Note I would like the SQL to keep the tuple comparison and not have this