Skip to content
Advertisement

Tag: database

Postgres Calculating Weighted Average

I am trying to get the weighted average of items from this example table: Item Value Item1 0.10 Item2 0.15 I followed this example here how to calculate it: https://www.wikihow.com/Calculate-Weighted-Average And tried this statement: I am trying to get the average by doing SUM(numberXWeightingFactor) but it doesn’t work. Ends up giving me error: column “numberxweightingfactor” does not exist. Answer Multiple

How to get columns which are not in GROUP BY?

I have a Postgresql database where I have these two tables. shipping_method shipping_details: id shipping_method_id estimated_time_min estimated_time_max price 2 1 02:00:00 04:00:00 230 3 2 00:03:00 01:00:00 500 4 1 02:00:00 04:00:00 1230 5 1 02:00:00 04:00:00 850 6 2 01:00:00 02:00:00 1785 My goal is to fetch the most expensive shipping details per shipping method (for a specific product

Php – cannot create new database record because primary key is null (autoincrement)

There are two tables: address and person. person_id (primary key, autoincrement) is a foreign key to address. I am trying to add an address record and person record from the same form but am getting this error. Uncaught Error: Attempt to assign property “person_id” on null in C:xampphtdocsappcontrollersMain.php:22 Stack trace: #0 [internal function]: appcontrollersMain->insert() #1 C:xampphtdocsappcoreApp.php(52): call_user_func_array(Array, Array) #2 C:xampphtdocsindex.php(4):

Calculate total units sold and total sales value

Can you help me check my answers whether is this the right way? Im really new to database This is the question This is my answer The reason i use with read only constraint was to enhance the security! Answer The way I see it, query would look like this: If compared to yours: don’t select columns you don’t need

How to decompose the tables for optimal querying

Suppose I have three tables Actor, Movie, Producer with following attributes Actor(Id,ActorName,Bio) Producer(Id,ProducerName,Bio) Movie(Id,Name,Description,ActorName,ProducerName) There can be many actors in a movie and actor can act many movies, same goes with producer. How to effectively decompose/create new tables to store data. I tried creating a new table with following schema ActorMovie(Id, MovieId, ActorId) but failed as there can be multiple

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

Finding the intersection between two integer arrays in postgres

In postgres documentation I found that if I have two intarrays I can use the & operator to get the common elements between the two arrays(intersection), but this statement: raises this error: I have postgresql version 13 I am wondering why doesn’t this work, and how can I fix the query or try another efficient alternative. Answer The documentation you

Advertisement