I have a table named tc_fuel that is receiving all the fuel related data from GPS vehicles, and I want to get the last “Tank Usage” to calculate MPG for a whole tank, but the readings when the tank is …
Tag: sql
How can I select multiple columns while setting one of them as DISTINCT
I have 6 columns and I want to select data from them while fixing one column as distinct the Display should be the following: Answer Using ROW_NUMBER and TOP: But this assumes that the second and third column are part of what defines a “group” in your expected result set. If instead only Column1 d…
SQL separate for stored procedure
About SQL Server Management Studio stored procedure. The following variables ‘|’ I want to separate it from. How can I do it? ‘628391|28100|8304|3|1201129|12|Kg|M01|SERIOUSLY CHUNKY WOOL’ ‘627452|…
Subquery django query to get biggest disctint values from objects and return those objects
So I have this query that I need to re-filter to get just the biggest taken_at field’s value from distinct meter id, but I cannot get the django orm’s/sql part to makes this query. <QuerySet [<Reading: [127] meter installation: 29, type: 1, taken: 2019-10-07 16:06:48.101453+00:00 value: 78.0…
Update table data, fetched from another table
I have a table which is storing the attendance information on an employee and another table that’s storing the information about the shift of the employee which is basically a duty roster. Here is …
SQL Select row with max value in one column
I have the following query SELECT Dnumber, SUM(WORKS_ON.Hours) AS sum_hours FROM DEPARTMENT JOIN PROJECT ON DEPARTMENT.Dnumber = PROJECT.Dnum JOIN WORKS_ON ON PROJECT.Pnumber = WORKS_ON.Pno …
Create table with composite attribute/columns in sqlite3
I have to create a Table in the SQLite database, however, I am unable to find the syntax where I can define composite attribute/columns while creating the table.In this ER diagram, I have a composite attribute as a DateOfPurchase of the Bicycle So could some please help me with this, Thanks in advance. Answer…
Trouble inserting value into a TEXT column with Postgres
I am getting an error when I try to insert an alphanumeric value into a TEXT column in a Postgres DB. This is the table definition ]1 This is the query I am using to insert data into the table This is the error message I get ERROR: syntax error at or near “a0032000947363339343638” LINE 12: 55.2047…
Build combined table from 2 uneven tables
I have 2 uneven tables which I am trying to build into 1 table, each table has a date and ID to join with, the issue is that sometime 1 table can have rows with no matching date in 2nd table Initially table 2 seemed to always have an entry for table 1 so I was doing a left join
Write a select query that displays “id” if a different “id” has same “panum”
The question i need to answer: “Display a list of academics that have collaborated with another academic on more than one paper. List individual pairs of academics on each line. List only their academic numbers. Do not list duplicate pairs. (e.g 56,113 and 113,56 are duplicate pairs)” So far iv be…