I would like to write a sql query where I choose all rows grouped by id where the column date is the latest date for this id but still smaller than for example 16-JUL-2021. I would like to do this without using subqueries (in oracle), is that possible? I tried the below but it doesn’t work. Answer You c…
Tag: sql
MySQL : calculate SUM of a Query
i have a mysql query that looks like this : The query returns a table b : I want to do the sum of those values By but it doesn’t work because of a syntax error. is it possible to sum a query like this ? Thanks. Answer Try this:
Group by name and return row with most recent date
Suppose you have the following data: What would be the best way to group by name and return the row with the most recent date in Snowflake (ANSI SQL)? Expected output: Answer With QUALIFY you can keep the newest per name As you will see in the doc’s it’s the same as Tim’s answer without the …
using python I’m trying to insert ADMIN_ID as None in to a database in SQL and my date_time that converted into a suitable format into a table
this works but i cant seem to get the other format to work i know that the date_time will work becasue ive already tested it on its own in a another database but i can seem to get this one to work InterfaceError: Error binding parameter :EXPIRE – probably unsupported type. Answer Use the following: [dat…
Improve Query to not have to run multiple times?
I currently have this working query. However, I have to run it multiple times with different parameters to get the total result. I’m wondering if there’s a way I can run a loop or create a column for each query within one query so I can get the complete result without commenting in specific params…
Correct database after backup
I need some help with a query. Actually we have some wrongs DATA in our database. For some technical reason I restore the backup in another schema. So actually in my Schema1.DB1.TBL1 I got the backed up DATA and in my Schema2.DB2.TBL2 I have the same table but with some wrongs DATA. Could you please tell me a…
Re-format table, placing multiple column headers as rows
I have a table of fishing catches, showing number of fish and total kg, for all the fishing days. Current format of the data is showing as below In the other reference table is a list of all the official fish species with codes and names. How can I re-format the first table so the rows are repeated for each
Get Value in Date Range with date parameter
Given 2 tables: Table A Table B I want to produce the following View: My Question, how to get Table A Value inside of that view, based on that transaction date within Table A Date From and Date To? Answer This query will match each table_a entry to every table_b transaction, based only on the transaction date…
Why does my SQL Statement not SUM() up correctly?
I have the following statement: note that = (1 or 4) refers to two statements in the database where 1 is sold and 4 is a refund. With = (1)) I get the following results: Costs – Unitamounts 3.281,10 – 582 With = (4)) I get the following results: Costs – Unitamounts -115,2 – -32 With = …
Using new columns created from PARSENAME
I have split the column PointName using PARSENAME and created 2 new columns and I am needing now to use a WHERE clause to only pull the data for those 6 types. Is there a way to do this? Answer Filling in the blanks a bit, but I would guess you could move the PARSENAME to the FROM and then