-1

I am working on one erp where i want to create pdf of each month of every user.

for that i have some data in mysql. i am attaching image of my table with data.

In pdf there will some fields should be display like particular user's this years net_salary, how many days he worked for this year etc.

For that basically i have to use SUM(column_name) with some conditions, but i cant get logic that if user will have 2018's 12 months data into database but user want only october month's salary_slip.

So now i want to display his 2018's SUM(net_salary) but till october months only. November and december's data should not be there in calculation.

I dont know how to create query for this.

enter image description here

Strawberry
  • 33,750
  • 13
  • 40
  • 57
amit sutar
  • 541
  • 2
  • 11
  • 37
  • 1
    See https://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-a-very-simple-sql-query – Strawberry May 06 '18 at 16:44

1 Answers1

1

You can put query having the dates inside a condition.

Example, if you want the sum between the months of January and October:

SELECT SUM(net_salary) FROM `your_table` WHERE pay_from > '2018-01-01' AND pay_to < '2018-10-31'

Or by using BETWEEN...AND

SELECT SUM(net_salary) FROM `your_table` WHERE pay_from BETWEEN '2018-01-01' AND '2018-10-31'

See more How to select date from datetime column?

Kearl
  • 86
  • 5