Sample Header Ad - 728x90

Query to select specific columns based on current date

0 votes
2 answers
787 views
I have a table named 'mrtg' that has four columns: mysql> select * from mrtg; +----------+------+------+------+ | city | day1 | day2 | day3 | +----------+------+------+------+ | Delhi | 2 | 6 | 9 | | Mumbai | 1 | 3 | 8 | | Banglore | 4 | 1 | 6 | +----------+------+------+------+ 3 rows in set (0.00 sec) If current date = '2019-09-01' then I want to select as SELECT CITY, DAY1 FROM MRTG; If current date = '2019-09-02' then I want to select as SELECT CITY, DAY1, DAY2 FROM MRTG; If current date = '2019-09-02' then I want to select as SELECT CITY, DAY1, DAY2, DAY3 FROM MRTG; and so on. How can I write a query for this? The values represent day-wise data for a whole month. I do wonder about this type of table structure, but it's the client requirement. I need to find a solution to fetch only the columns from day 1 to the current date.
Asked by AAMIR KHAN (1 rep)
Sep 3, 2019, 06:57 AM
Last activity: Jul 2, 2025, 07:01 AM