mercredi 21 janvier 2015

SQLite - find a certain value and find the highest value on another column on the row input value appears then select all the elements on that row

I am using sqlite3 library on a c project. And I have a database like this:



| Time | Message | ID | Temp |
|--------|-----------|------|--------|
|09:05:37| 1514 | 62 | 35 |
|10:14:45| 1515 | 43 | 14 |
|11:18:50| 1997 | 28 | 43 |
|08:04:23| 1998 | 28 | 50 |


Message is an autoincrement value. What I am trying to do and my questions are:



int ID_in;
printf("Enter the ID you want to check: ");
scanf("%d", &ID_in);


Firstly user will input a value and I have to find does that value appear on ID column and if it appears I can start my operations. Since user will input a value should I use a sqlite3_bind() function on my database to compare the ID_in with the values on database?


If the ID_in appears on the ID column I have to find the highest value on the Message column which is on the same row with ID_in value since there may be more on than one ID_in value on the ID column. For example if the ID_in is 28 I have to access the row which Message value is highest, for this one I have to access the row where Message value is 1998.


After I access that row I should print all the columns on that row. For example if ID_in is 28 find the value 28 on ID column. Then find the highest Message column value which is 1998. Then print Time, Message, ID, Temp on that row which are 08:04:23, 1998, 28, 50 for this example.


Aucun commentaire:

Enregistrer un commentaire