SQL add comma seperators on an integer value [duplicate] - mysql

This question already has an answer here:
MySQL - Thousands separator
(1 answer)
Closed 9 months ago.
I have a query:
select sum(invoiceamount) as invoice
from fact_salescount
where year in ({YEAR})
and month >= ({FROMMONTH})
and month <= ({TOMONTH})
This query can return a value from 100.00 to 15034115.93. It will return ONE value.
I would like to add, for each 000, like this: 15,034,115.93
I've seen a lot of similar questions, but none match mine. I hope someone can help me out.
I am using Pentaho and MySQL, and creating these queries within the Design Studio.

SELECT FORMAT(sum(invoiceamount),2)
FROM fact_salescount
WHERE year IN ({YEAR})
AND month >= ({FROMMONTH})
AND month <= ({TOMONTH})
This should do what you want, but I still don't like formatting number in the backend.

Related

How to calculate the number of days between two dates in sqlite or mysql? [duplicate]

This question already has answers here:
How to get the number of days of difference between two dates on MySQL?
(8 answers)
Closed 4 years ago.
How to calculate the number of days between two dates available in sqlite or mysql database table?
I have already searched it on google but couldn't found any solution.
What is proper query for getting number of days between two dates?
the query should look like this, MySQL:
SELECT datediff(current_date(), '2018-10-01') AS numberOfDays FROM dual;

Return SQL query in specific chunks? [duplicate]

This question already has answers here:
Interleave rows of MySQL table
(2 answers)
Closed 5 years ago.
I have a time stamped data for specific dates in my mysql database. Whenever I retrieve the data in different ways, this is what I usually get:
I'm trying to get this query to look like this
What I want is to return different/distinct rows for date1 while keeping time ordered. If you look at the desired result, you will see that date1 starts with Sep then Oct then goes back to Sep, Oct etc. I hope this makes it clear.
Note: This is just an example, the real data have four different dates in date1 column so I'm expecting every four rows to have a different entry of date1
If I understand your question correctly, you just need to specify an order by clause.
select
...
from
...
where
...
order by
date2
, time

Go Back To Beginning Of Month On Input Date MySQL [duplicate]

This question already has answers here:
How to get first day of every corresponding month in mysql?
(15 answers)
Closed 5 years ago.
Let's say that I have an input date of "2017-01-31" or "2017-02-28". I want to take this input date and make SQL change it to "2017-01-01" or "2017-02-01".
Is there a way to do this via MySQL functions in a query?
Several ways to do that. My preference is to use DATE_FORMAT to replace the day portion with constant 01.
SELECT DATE_FORMAT('2017-01-31','%Y-%m-01') + INTERVAL 0 DAY AS dt
There are lots of ways to skin that cat.
For example, we could subtract the integer number of days minus 1 ...
SELECT '2017-01-31' + INTERVAL 1-DAY('2017-01-31') DAY
(With the second form, the date value needs to be supplied twice. With the first, we only need to supply the value one time. I think the first form is easier for a future reader to understand... pretty clear what the author is intending.)
Use your date instead of my example:
SELECT CONCAT_WS('-',YEAR('2017-01-28'),MONTH('2017-01-28'),'01')

Mysql date problem [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Select by Month of a field
i want to get the data from database whose month is 7. means
My Date format is
PostDate datetime
now i want to query..
select * from tabelname where PostDate = 7
If you are asking how to query MySQL for date objects based on month, then this may be your answer.
select * from tablename where month(PostDate) = '07';
Keep in mind this function (month()) is MySQL specific.

Finding difference between dates [duplicate]

This question already has an answer here:
Closed 11 years ago.
Possible Duplicate:
trying to get the number of months
I have a
memberpayments table
totalamountpaid
exppayments
expmonthly payments
dueday
memberid
I want to find the datediff like this way here I have found the date diff using c#
but I want to find the date diff using mysql
double equivalentPayments = totalamountpaid /expmonthly payments;
double monthdiff = Math.Ceiling(exppayments - equivalentPayments);
monthdiff -= 1;
int dueDay = 01;
DateTime expDate = DateTime.Today.AddMonths((int)monthdiff).AddDays(DateTime.Today.Day - dueDay);
int diff = DateTime.Today.Subtract(expDate).Days;
I have tried using Date diff but it was giving the difference between two dates and it was not giving datediff like above solution(c#).
can i get these statements all in one query......using mysql....
would any one pls help me out
MySQL have a large set of date time functions. Finding differences between dates are fairly trivial using them :)
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html
If i understand correctly, all you are after is the difference in days between two dates. This can be done with DATEDIFF(a,b) :)