Saving reports query to database - mysql

I am developing an web app that is reliant on reports being dynamically generated. The client has specified they would like to save reports searches to the database for future use, specifically generating reports from the last 6 month.
I can add the query to the database no bother, the problem is trying to get the date to be dynamic depending on the date the report is ran. The 3 types are bi-monthly, monthly and 6 monthly reports.
My question is:
How would I go about saving the query and getting it to calculate the current date and search based on the report type (2, 3 or 6 month). Is it a simple case of editing the sql query when I pull the query from the database, or would it be easier to split up the query into different parts to make it easier to manipulate/edit later.

Create a second column in your table where you store the query with the dynamic column. Use that column in your dynamic query

Related

MySQL Storing Reports

I am looking for a way to store auto-generated reports. There are about 10-15 columns and 100-3000 rows depending on the report but each report is consistent in column count.
I am looking for a way to organise and store these reports into a large group without creating an entire new database and 1000s of tables to store each indervidual report.
The reports need to be queryable so they can be subdivided by team/area/person etc as each report can be a combination of 3-4 different sub-reports depending on how you split/sort the data.
I am using Python to collect and sort the data from the database so using MariaDB/MySQL would be preferred but im happy to use something else if there is a pre-exising connection libary for it.
To sum up i need something similar to a excel spreadsheet with each table being a sheet and sheet name being the date it was generated so i can select by the date generated.
Think through the goals.
Is this a legal issue -- you need to produce an unalterable report as something "official". A la a non-editable .pdf?
(at the opposite extreme) Be able to generate (or regenerate) any report for any timeframe.
Is performance an issue? (Either perceived or real)
I like to build and maintain Summary Table(s) for any "Data Warehouse" application. And build "reports" that take as a parameter a date range and a small number of other things. And have the report generation so fast that it does not matter if multiple people are pulling reports at random times.
15 columns and 3000 rows is usually excessive. If pulling a report is trivial enough, it can be less 'massive'; just get the parts you want, without such bulk.
http://mysql.rjweb.org/doc.php/summarytables

MySQL: Dates as column headers

I'm trying to develop a new reporting module for a resource management tool (PHP+Mysql).
I am trying to extract data in the following format from mysql:
I have a table that consists of date and location of multiple people(i.e Office, Home or Client).
Sample Data as in DB.
here date_plotted means the date at which the user is engaged and plotting_date represents when this particular entry was made in the system(the date). So User was plotted to be in office on 30th Oct and the same entry was made on 30th Oct.
Data as in resource table
The resource table represents the user table.
Any suggestions on how to do the same in mysql?
These are the primary tables which needs to be used.
The above table id done in excel for now to represent the outcome.
I'm new to SQL so haven't tried anything yet.
There is a tool for Windows that might simplify this operation. It's made by MySQL and called MySQL for Excel. In theory it should allow you to structure and make changes to MySQL databases as well as perform queries that result in spreadsheets.
Without knowing more about your data, for example being supplied an actual csv file to work with, and the parameters of the actual pull, whether it's fix dates always or if this is a dynamic pull based on a range this question could result in 100 different implementations that visually return similar results, but have massively different requirements overhead-wise in implementation.

How do I store data pertaining to a month or year in Mysql

I receive csv files at the end of each month from my customer for each of their KPI (for example csv's for resumes received, candidates joined, candidates resigned, sales, profits, loss , etc) for that specific month.
I want to be able to query this data inorder to generate reports for any month, day or year. This report will be generated dynamically i.e the admin would specify what rows he would like to have in a report (for eg a report with applications received, applications shortlisted, candidates shortlisted after the 1st interview for the period of jan to july.) for any period of time.
What would be the best way to store the data into my database in order to generate such reports? I am using Mysql as my database.
I am not sure if I would need to flush out the old data from my tables currently. So considering that I keep all the data persistent, what would be the best suited database design for this?
Currently what I do is I have a table for each of their KPI. This table has got a date field which I am using to generate the report. But I am looking for a more optimized way.
Thanks in advance.
It is better to store those values (month or year related values ) in a "Date" type fields which would not need any other manipulation while building reports. The conditions or logic for the specific period of time should be handled in your front end. In this case, the usage of Date field is the optimized way.

Database structure for variable column names [duplicate]

I am writing a script which will counts the number of ticket as per as different conditions and store the count in a summary table. I am unable to understand how to structure my table since there will be more than 1 variables.
The script will run every week and with each execution a new week will be added. Once the new month starts and scripts execute, a new month will be added and once new year starts a new year will be added. So in a nutshell I have columns which are also variables. Not sure how to handle it and structure my db.
Have columns Date Service Count.
Like so.
Date Service Count
16 May 2016 Service1 35
Then when you go to display them in the report pivot them as you want. Probably better to make date an INT and either an auto number PK or composite PK of Date and Service.
Wrong approach. Do not splay an array across columns. Instead have rows for the data. This lets you trivially "add" another month.
For displaying, well that is an application problem, no a MySQL problem. Sure, you can write specialized queries to "pivot" the data from rows to columns, but it is messy.

Need to write SSRS report that uses stored procedure with a pivot as a dataset but I can't get the report to be dynamic, is this even possible?

I have a bear of a problem here. The user wants a report that shows the earnings, deductions and liabilities (EDL) code of each employee or null/blank if an EDL code doesn't apply to that employee. I needed one row for each employee name and columns for each possible EDL code combination. I got that answer fixed from my previous question here:
Struggling with a dynamic pivot on multiple columns with one being concatenated
I ran into a problem where there are a potential 270 column headings (EDL code combination with "subj", "elig" or "amt" appended) but not every employee will have a value for every column and security settings lock me out of seeing 1 of the 3 payroll groups. This made my report very limited in that when I ran it I could only show on the Crystal Report the data for what columns I had at the time I created the Crystal Report. Well, the user who requested this report has access to payroll group 1 and if even one of those employees had an EDL code that I didn't have in my data when I created the Crystal Reports file then the report wasn't useful to the user. We figured a way for her to get the info she needed by her logging into SQL Server and executing the stored procedure and she did what she needed to do with the data.
Fast forwarding to today I have to create this as a report in SSRS or give detailed instructions on how she can do this in the future if need be since my contract is coming to an end. I'm not familiar with SSRS but I thought maybe that would meet her needs over Crystal Reports. However, I'm running into the same problem. When I add the stored procedure as a dataset (adding it in as text to execute, not clicking the stored procedure radio button) I only see the EDL codes from that particular query not all potential combinations. I need a way to maybe dynamically add columns to the SSRS report, does such a thing exist?