I have a table in the database that the date fields are of type BigInteger, in which it receives a date in the format Timestamp.
How do I make a SELECT
in the table with the following conditions:
SELECT
COUNT(log.id) AS QTD
FROM
mdl_logstore_standard_log log
INNER JOIN mdl_user ON mdl_user.id = log.userid
AND suspended = 0
AND deleted = 0
WHERE
MONTH (
from_unixtime(log.timecreated)
) = MONTH (now())
AND YEAR (
from_unixtime(log.timecreated)
) = YEAR (now())
AND action = 'loggedin'
AND userid > 1
GROUP BY
MONTH (
from_unixtime(log.timecreated)
),
YEAR (
from_unixtime(log.timecreated)
)
I need it to be the month and year number. But I do not know how to convert the date using the Django Database API. I have this down so far:
totalAccessMonth = Log.objects.filter(timecreated__month = now.month).all()
What I want is to convert the column in real time to a date type. The field currently in base is bigint
. I can not change it in the bank.
I need this query in the form of Django.
For now I have this:
Log.objects.filter(action = 'loggedin', userid__gt = 1) \
.extra(select={'timecreated_year' : 'YEAR(FROM_UNIXTIME(timecreated))'}) \
.extra(select={'timecreated_month' : 'MONTH(FROM_UNIXTIME(timecreated))'}) \
.values_list('timecreated_month', flat = True) \
.aggregate(Count('id'))