dexterous
dexterous

Reputation: 6526

How to run a single query to achieve the following result?

I have the following table -

ID  Start Duration
1   343     342
1   434     32
1   562     12

I want to run a query in sql-lite to get the first start, last start and last Duration and number of such ID's.

I tried following to achieve this.

SELECT MIN(Start),COUNT(ID) FROM event_list where ID=1 ORDER BY Start;

With this, I am able to get the First Start and the number of ID's. But, I want to get the Last Start + Last Duration. i.e. 562 + 12. However, I don't have the LAST function supported in the sql-lite. How can I achieve it?

Upvotes: 0

Views: 49

Answers (2)

Thrash Bean
Thrash Bean

Reputation: 658

SELECT duration 
FROM event_list 
WHERE start = (SELECT Max(Start)  
               FROM event_list 
               WHERE ID=1);

or

SELECT duration , 
       Max(Start)  
FROM event_list 
WHERE ID=1;

Upvotes: 1

Yasser Z. Abbass
Yasser Z. Abbass

Reputation: 11

Have you tried (select Duration from event_list order by Duration DESC limit 1) as Sub Query for the LAST function ?

Upvotes: 0

Related Questions