Skip to content
Advertisement

Retrieve columns from three tables

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

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

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

Advertisement