I am trying to query a huge database (aprroximately 20 millions records) to get some data. This is the query I am working on right now.
SELECT a.user_id, b.last_name, b.first_name, c.birth_date FROM users a
INNER JOIN users_signup b ON a.user_id a = b.user_id
INNER JOIN users_personal c ON a.user_id a = c.user_id
INNER JOIN
(
SELECT distinct d.a.user_id FROM users_signup d
WHERE d.join_date >= '2013-01-01' and d.join_date < '2014-01-01'
)
AS t ON a.user_id = t.user_id
I have some problems trying to retrieve additional data from the database. I would like to add 2 additional field to the results table:
Or you can do just this ...
SELECT
TIMESTAMPDIFF(YEAR, birthday, CURDATE()) AS age_in_years,
TIMESTAMPDIFF(MONTH, birthday, CURDATE()) AS age_in_month,
TIMESTAMPDIFF(DAY, birthday, CURDATE()) AS age_in_days,
TIMESTAMPDIFF(MINUTE, birthday, NOW()) AS age_in_minutes,
TIMESTAMPDIFF(SECOND, birthday, NOW()) AS age_in_seconds
FROM
table_name
Try this:
SELECT a.user_id, b.last_name, b.first_name, c.birth_date,
FLOOR(DATEDIFF(CURRENT_DATE(), c.birth_date) / 365) age,
DATEDIFF(b.left_date, b.join_date) workDays
FROM users a
INNER JOIN users_signup b ON a.user_id a = b.user_id
INNER JOIN users_personal c ON a.user_id a = c.user_id
WHERE b.join_date >= '2013-01-01' AND b.join_date < '2014-01-01'
GROUP BY a.user_id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With