Code With Coffie
  • HOME
  • ABOUT US
  • PORTFOLIO
  • JAVASCRIPT
    • Vue.js
  • PHP
    • PHP OOPS
    • LARAVEL
    • WORDPRESS
  • MYSQL
    • DATETIME
  • DSA
    • LEETCODE
  • Home
  • Blog
  • MYSQL
  • DATETIME
  • πŸ”₯ Advanced Level Date-Time Questions in MySQL

πŸ”₯ Advanced Level Date-Time Questions in MySQL

Jun 13, 2025 by codewithhemu

1. Current quarter

WHERE QUARTER(col)=QUARTER(CURDATE()) AND YEAR(col)=YEAR(CURDATE())

2. Last quarter

WHERE QUARTER(col)=QUARTER(CURDATE()-INTERVAL 1 QUARTER) AND YEAR(col)=YEAR(CURDATE()-INTERVAL 1 QUARTER)

3. Cumulative monthly sales

SELECT month, SUM(amount) OVER (ORDER BY month) FROM (SELECT DATE_FORMAT(col,'%Y-%m') AS month, SUM(amount) AS amount FROM table GROUP BY month) AS t;

4. Rolling 12-month summary

WHERE col >= CURDATE() - INTERVAL 12 MONTH GROUP BY DATE_FORMAT(col,'%Y-%m')

5. Avg login-duration

SELECT AVG(TIMESTAMPDIFF(SECOND,login,logout))/3600 FROM sessions;

6. Overtime >9β€―hrs

WHERE TIMESTAMPDIFF(HOUR,in_time,out_time)>9

7. Multiple logins/day

SELECT user_id, DATE(login), COUNT(*) FROM logins WHERE login >= CURDATE()-INTERVAL 7 DAY GROUP BY user_id, DATE(login) HAVING COUNT(*)>1;

8. Top‑5 busiest order days

SELECT DATE(col), COUNT(*) AS cnt FROM orders GROUP BY DATE(col) ORDER BY cnt DESC LIMIT 5;

9. Weekday vs weekend segments

SELECT DAYOFWEEK(col)<=6 AS is_weekday, COUNT(*) FROM table GROUP BY is_weekday;

10. Convert UTC to IST

SELECT CONVERT_TZ(col,'UTC','Asia/Kolkata') FROM table;

11. Create view for current week

CREATE VIEW this_week AS SELECT * FROM tbl WHERE YEARWEEK(col,1)=YEARWEEK(CURDATE(),1);
  • Share:
Previous Article πŸ”₯ Medium Level Date-Time Questions in MySQL
Next Article What Are Laravel Contracts
No comments yet! You be the first to comment.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

category

  • DATETIME (6)
  • DJANGO (1)
  • Docker (1)
  • DSA (21)
  • DSA PRACTICE (4)
  • ENGLISH READING (1)
  • JAVASCRIPT (69)
  • LARAVEL (40)
  • LeetCode (1)
  • MYSQL (45)
  • PHP (21)
  • PHP OOPS (16)
  • PROGRAMME (1)
  • PYTHON (7)
  • REACT JS (6)
  • STAR PATTERN PROGRAMME (7)
  • Uncategorized (20)
  • Vue.js (5)
  • WORDPRESS (15)

Archives

  • March 2026
  • October 2025
  • September 2025
  • August 2025
  • July 2025
  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • January 2023

Tags

Certificates Education Instructor Languages School Member

Building reliable software solutions for modern businesses. Sharing practical tutorials and real-world project insights to help developers grow with confidence.

GET HELP

  • Home
  • Portfolio
  • Privacy Policy
  • Terms & Conditions
  • Disclaimer
  • Contact Us

PROGRAMS

  • Software Development
  • Performance Optimization
  • System Architecture
  • Project Consultation
  • Technical Mentorship

CONTACT US

  • Netaji Subhash Place (NSP) Delhi
  • Tel: + (91) 8287315524
  • Email: contact@codewithcoffie.com

Copyright Β© 2026 LearnPress LMS | Powered by LearnPress LMS