-7

I have a table "empdata" it contains fields create date, last modified date, emp id. In order to check count am running query "select count(*) from empdata". Now I need query where I have to get results till yesterday's date.

for example:

select count(*) from empdata
output: 23

select count(*) from empdate ( I need condition here for yesterday's date)

output:20

Note: **I need to use this query in java program so I cannot give yesterday's date in query. Java program will be running daily so date gets* changed daily.*

Shadow
  • 33,525
  • 10
  • 51
  • 64
Jhansi
  • 9
  • 1
  • 10
  • 1
    Just one database at a time or asking for a generic SQL solution would be best here. Which system are you running on? What's the column indicating the date? – tadman Apr 26 '16 at 06:07
  • useful link for you http://stackoverflow.com/questions/11425236/get-yesterdays-date-using-date – JYoThI Apr 26 '16 at 06:09
  • createdate is column indicating. am running in db2 – Jhansi Apr 26 '16 at 06:24
  • Then why on earth did you tag the question with mysql and ms sql tags in the 1st place? And why did you not remove them once your attention was called to the problem? – Shadow Apr 27 '16 at 05:39

1 Answers1

3

Use this query to get the results, te condition you've asked should be

where create_date < current_date()

select count(*) from empdata where create_date<current_date()

You have mentioned that you want to run this program in java, Try jdbc

http://www.tutorialspoint.com/jdbc/

edit:

use CURRENT DATE instead of current_date() in the above query for db2

Andrews B Anthony
  • 1,381
  • 9
  • 27