I have the following dataset, that have the prices for many products and cities: CREATE TABLE my_table ( the_id varchar(5) NOT NULL, the_date timestamp NOT NULL, the_city varchar(5) NOT …
Tag: sql
Only show rows in a table if something changed in previous row
I have a table with a lot of records (6+ million) but most of the rows per ID are all the same. Example: Row Date ID Col1 Col2 Col3 Col4 Col5 1 01-01-2021 1 a b c d e 2 02-01-2021 1 a b c d x 3 03-…
MS Access query that includes a join to itself (using a subquery) and reports values that do not exist (null values)
I have the following table named PRICES: VERTEXID TIMEID PRICE 6001 20191231 104.3 6001 20181231 115.3 6001 20171231 138.3 6001 20161231 122.3 6002 20191231 102.3 6002 20190931 123.3 6002 …
Provide array of ids and get rows with repeated rows
I have the table where I wand to do a query to get same rows multiply times Races Table: id name location 1 fast race London 2 cool race New York 3 super race Berlin I want to do query where I will search races in table by id and get results with repeated rows something like this And get
LIMIT 1 by Column On Query Returning Multiple Results?
I have a user_certifications table, with these props: So, a user can be listed multiple times with a variety of certs. I have a list of user_ids for which I need to get ONLY the most recently updated record. So for one user it would be: How do I do this efficiently if I need ONLY the last dated entry
sql find parent table where sum of child column not equal to parent column
hey guys i am trying to find the a bill from billMaster where the sum of billDetails.total is not equal to billMaster.remainingAmount NB this is a one to many relationship where one bill can contain more billdetails i tried the below query and got an sql error both queries returned the same error i gess its o…
Update column value to be minimum of all column values before it
I have a table, which when sorted according to the week number gives the units left of a product at a store. The units left should always be decreasing. However, there are some garbage values due to which the units left in a store increases for few weeks and then decreases again. I just have these four column…
SQL Select One Record over another based on column value
What I am trying to do is select rows based off of a ‘priority’. Say I have this: I want to choose one row each for the control ids (the whole row), which would be the third row, because there is no priority, and the 2nd row becuase it has priority. So if I have two control IDs that are
ORA-04091 TABLE ODB.EMPLOYEE IS MUTATING, TRIGGER/FUNCTION MAY NOT SEE IT. IS THERE SOMETHING WRONG WITH MY TRIGGER?
Trying to create a trigger when there is an update of Status on Employee Table and capture some values for the record in Employee table and Employee_Header table for that record and send an email. The trigger throws an error. Answer You can’t select from a table which is just being changed; it is mutati…
How to sum and pivot a table in SQL?
I have the following table: col_a col_b col_c 1 0 1 0 1 0 I want to sum up each column and assign a value to it based on the output, with the output like-so below: column sum string col_a 1 ‘string one’ col_b 1 ‘string two’ col_b 1 ‘string three’ I’ve tried the follow…