I just started with triggers, I want the trigger to give me the msg error if the new tauxHoraire is 50% greater than the current tauxHoraire (so *1.5 >). The trigger compiles but I’m getting ORA-04091: table name is mutating, trigger/function may not see it. There might a problem in how I wrote it. O…
Tag: sql
SQL to select the value of a column matching multiple values in another column?
I have a Chat_User join table, and want to retrieve the ChatId of a between specified UserId of x and y. Chat_User table: I tried: But it returns ChatId of a and c, but I only want a, as it has BOTH of my specified UserId(x and y). Any way to achieve this? Thanks Answer Aggregation offers one approach:
Return list of Students by ZipCode Count
I am trying to get a list of students that live in the same zip code where zip code count > 1. I tried the following and get nothing in my query. If I remove s.Student, I get results of zipcode and count, but I want to include student also. Below are the database tables I am using. Answer I
How to get a SQL trigger to increment by 1 on an update?
I am trying to create a trigger that updates one column on a specific row when it is updated but I am getting this error ORA-04091: table table_name is mutating, trigger/function may not see it when I go to test the trigger. This is my trigger code: It is suppose to only update that certain Employees ID revis…
Consolidating an SQL UPDATE statement using same table and multiple variables and WHERE IN clause
I have a single table table1 where I am trying to update one column completed to certain values based on id. Because the table remains the same as well as the updated column and WHERE clause field, I have been looking into the potential of consolidating the SQL statements. I have a table1 like this: Here is a…
How to update multiple columns on PostgreSQL with values from another table
I have the following update statement: but.. what if I have more values that need to be updated? Do I need to: This looks expensive. Couldn’t find any other way though. Answer One way is to update both columns in a single expression:
Convert SQL commands to Python
I have the following code in SQL: I’ve been trying to rewrite it in python like so: but I keep getting a generic error message. What am I doing wrong? EDIT: added the error message Answer IIUC, you could try the following: The equivalent of SELECT DISTINCT col is drop_duplicates(col) and the equivalent …
How to find employee department changes?
I have a table that has the old departments and new departments of various employees: EmployeeID OldDept NewDept 123 Design Design 234 Software Engineering 345 Design Software 456 Advertising Software How can I create a table that looks like this: Dept TransfersIn TransfersOut Software 2 1 Design 0 1 Advertis…
Sum of Current + Previous X Nth Rows
I am looking to find the sum of the current + the last X Nth Rows. I am able to do this with the following query, however it is not very scalable. If this example, I’m finding the current value of “amount”, plus the last 3 “amounts” split 6 apart: X = 3 N = 6 I will be using
SQL: How to combine values in column week (i.e. week 1, week 2, etc) into week range (week 1-2 or week 1, 2)?
General SQL question using online SQLite editor, if I have the following table: item week sales item1 1 35 item2 1 25 item3 1 24 item1 2 35 item2 2 34 item1 3 24 item2 3 45 item1 4 44 item2 4 51 item1 5 1 item3 5 100 how would I get the output to be this: item weeks