I have an application that uses coordinates. I want to select records within 5 km that were thrown in the last 5 minutes. How can I do this easiest? I want to write a procedure. The values I will send to the procedure are latitude (float 11,8) and longitude (float 11,8). Example table: I found a query like th…
Running assignment of values with break T-SQL
With the below table of data Customer Amount Billed Amount Paid Date 1 100 60 01/01/2000 1 100 40 01/02/2000 2 200 150 01/01/2000 2 200 30 01/02/2000 2 200 10 01/03/2000 2 200 15 01/04/2000 I would like to create the next two columns Customer Amount Billed Amount Paid Assigned Remainder Date 1 100 60 60 40 01…
Deserialize Postgres ARRAY [@tags] to List with Dapper?
I’m using Dapper with Npsql (Postgres). I’m saving a serialized list of strings to one column called tags: which is resulting in {{first,second}} in the database. My question is how to read it back to the model? Do I need some special SQL, or can I use SELECT id, text, tags FROM account;? How can …
PostgreSQL limit by variable value in a CTE
I am trying to fetch some results from the database using two SQL select queries, I am using CTE, but since I have millions of rows I need to limit the results, I want to limit results to 20, what I tried is: Aggregate functions don’t seem to work on limit, moreover, even if they do, I would have a
Displaying Multiple Rows of Data from Two Tables with a One to Many Relationship
I have two tables. Tracks and metadata. Tracks can have multiple metadata attributes, but metadata can only be attached to a single track. The metadata table has a foreign key for a track ID, but the tracks table has no foreign keys for metadata. I am trying to find the best way to get this result: Essentiall…
Calculate SUM from one table and display columns from another
I have 2 tables, Employee, and Transaction Transaction tID cID carID eID tDate PickupDate ReturnDate Amount_Due Employee eID fName lName Job Manager Hired I need to calculate the commission (2.5%) and display that along with fName and lName. I’ve calculated the commission, I think I’ve done the jo…
How to use the passed data in to a sql query?
How do I pass the $id into my $record SQL query and what is the eloquent query as well? I want to do this because the user_id is the foreign key from borrows. I want to pull data from payment_records that have the same id with the selected id. This is the show method where I passed the id and
Creating a SQL view that will accept inserted values
I have created a SQL view that retrieves the result set I desire but when I try to add a new set of values it fails. When searching around on the net it appears that VIEW has a few limitations and some types of joins may not be allowed, I have tried to create the view a few different ways
DISTINCT and ORDER BY in the same command without using the order by variable
I need to select the recent 5 games the user has gone into but I don’t want there to be duplicates. So I need a SQL line that will take them in order from most recent to least but also make sure there are no distinct. To order them I have a time variable, but if I use: this removes
is it violate 2NF?
My table book PK ID INT pfK langID INT title VARCHAR description MEDIUMTEXT releaseYear YEAR chaptersPrice DOUBLE thumbnail BLOB Where pfk – Primary-Foreign Key; {ID, langID} – PK; chaptersPrice – price of each chapter of book. Example: BookName1: chaptersPrice=2 BookName2: chaptersPrice=3 I…