The data I am working on looks like below- A_ID B_ID count 123 abcd 1000 123 aaaa 2000 123 aaaa 3000 456 null …
Tag: greatest-n-per-group
select current address
I am new in sql and have a table as folow: patientid |gender|yearbirth|zipcode|admission | ———–|——|———|——-|——————-| P1213060727|w | 1926|55268 |2017-01-23 16:28:00| P1213060727|w | 1926|55270 |2018-09-26 18:1…
Get the last entered id from a table in sql
enter image description hereI have an employee table. In that table I have n number of loan.. Now I want to select all the employees with his last taken loan value and date.. can anyone help me out in this. There’s what I’ve done so far: I tried group by, limit and order by for this but of no use&…
How to query for city name as well as length of the smallest city name from the same table
My code is this but gives error, don’t know why. Please help! Answer If you just want the city with the shortest name, you can simply order by and limit: This returns just one row. On the other hand, if you want to allow bottom ties, then you can filter with a subquery, like so:
Top-N By Decade for successive decades (in SQL Server)
I’m trying to get a ranked list of Top 5 (i.e. most common) document titles, grouped by decade, for each of the 6 most recent decades. The document titles are non-unique. There could be dozens or even hundreds of documents with the same title in any given calendar year. The following query is as far as …
Row sorting and selection logic in Python on Sqlite db
hello Thanks for taking the time to go through my question. I work in the budget space for a small city and during these precarious time, I am learning some python for maybe in the future helping me with some financial data modelling. We use SAP currently but i also wanted to learn a new language. I need some…
Get the latest child messages and also parent messages that are childless
The following is the Message model message_participants has a record for each message and the various people who have sent or received that message. It has a user_id on it. The problem with the above latest_messages_by_participant scope is that it is able to get all the child messages BUT it gets only the las…
Fetch record from table?
I have table in which data is like this Mapping Relationship 1 task_id is mapped to multiple task_detail_id (1 to Many) Task_detail_id Task_id Creation_date 1 20 2020-05-…
Why this select selects no rows
I am trying to select a highest earner in ‘IT’ department, but I keep selecting no rows. Salary and names are in table called employees while department_name is in a table named departments. Can anyone please explain why does this select no rows and how should I do it? Answer Why this select selec…
SQL – get MIN value of row and check this MIN value to be in row at least 2 times
What I’m trying to achieve is this: 1) Get the minimum value of a salary in the table for every department. 2) If this minimum value exists in the table at least two times for every department, then …