I have data like this,

enter image description here

how do I get the total value from the previous transaction but not today, I try with queries like this

SELECT * FROM `stock` ORDER BY date_created DESC, time_created ASC

but the results are like this

| Valas  | Total | Date Created | Time Created |
| VLS001 | 13750 | 2019-05-13   | 15:15
| VLS001 | 13900 | 2019-05-11   | 14:30
| VLS001 | 13650 | 2019-05-11   | 15:39
| VLS001 | 13850 | 2019-05-10   | 15:20

i want to get result like this

| Valas  | Total | Date Created | Time Created |
| VLS001 | 13650 | 2019-05-11   | 15:39
| VLS001 | 13900 | 2019-05-11   | 14:30
| VLS001 | 13850 | 2019-05-10   | 15:20

I tried by making a query where date_created - 1, to get the results of the last transaction but not with today's transaction, but there was an error the previous day there was no transaction

1 Answers

1
Wallarou On Best Solutions

Add a WHERE clause on date_created column specifying that the value must be different from today's date.

SELECT * 
FROM STOCK 
WHERE date_created != CURDATE() 
ORDER BY date_created DESC, time_created ASC;