473,394 Members | 1,811 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Report with several queries

As a part of my case study, I got a scenario to produce the Employee report for the list of years.

It has following fields named Year, Name, Designation, DOJ, Salary (from table EMPLOYEE) and Total. I write a simple SQL query and produce the values in the report by mapping the corresponding fields.

Expand|Select|Wrap|Line Numbers
  1. ---------------------------------------------------------------
  2.         ANNUAL FISCALE REPORT - EMPLOYEE HUB
  3. ---------------------------------------------------------------
  4.  
  5. Year    Name    Role     DOJ         SALARY        TOTAL
  6.  
  7. 2015    TEST1     MANAGER    24/05/2015   $12,000.00    
  8.      TEST2     VP    12/04/2015   $15,000.00    
  9.      TEST3     VC    01/02/2015   $13,500.00       $40,500.00    
  10.  
  11. 2014     TEST4     MANAGER    25/03/2014   $15,000.00       $15,000.00    
  12.  
  13. 2013     TEST5     MANAGER    03/12/2013   $12,000.00     
  14.      TEST6     VP    23/08/2013   $18,000.00    $20,000.00 
  15.                            ----------
  16.                                        $75,500.00
I have below listed conditions should be satisfied for the aforementioned requirement of report.

YEAR column: Display Value only once for the FIRST ROW for Maximum value of DOJ field value for each set of YEAR. If it has only one record, it display that year.
I will be writing my SQL QUERY ORDERBY DATE_OF_JOINING (DOJ) in DESCENDING sequence. So it will display the records in aforementioned order. But i have no clue how to supress or reset the YEAR value for other records (Other than first row) for each set of year


TOTAL Column: Display Total Value for SALARY field only once for the LAST ROW of each set of year record. I will use SUM function to add those salary fields to get total value. While displaying, how to make it available only for last record alone ?


Jul 1 '15 #1
2 1535
zmbd
5,501 Expert Mod 4TB
This appears at first glance to be a homework question and such threads without work shown are often closed or removed, even if answered by another member.

HOWEVER If you will show your work, often someone here will provide some hints... better to teach than to dismiss :)

One such hint, establish >> Database Normalization and proper Table Structures.
The SQL will almost write itself at that point (well... maybe not that easy... :) )
Jul 2 '15 #2
Hi Friend,

Thanks for the instruction. As this is my first post, i will correct it from now on.

My Requirement is to generate the report using VBA - SQL query by accessing the MS Access tables. attached the format of new report.

I have no clue how to get the required output in a single query.

Whereas, i wrote two separate queries.

Query 1: This query generate the list of records with fields Anno (year), Data_Movimento (Date), Note description and Agent description in descending order.

Expand|Select|Wrap|Line Numbers
  1. SELECT CessioneCredito.Importo, CessioneCredito.Anno, CessioneCredito.Data_Movimento, CessioneCredito.Note_Liq_Cessione_Credito, Agenzie.Denominazione
  2. FROM CessioneCredito INNER JOIN Agenzie ON CessioneCredito.ID_Agente=Agenzie.ID_agenzia
  3. WHERE (((CessioneCredito.ID_Agente)=[Reports]![R_StoricoCessCredAg]![ID_Agente]))
  4. ORDER BY CessioneCredito.Data_Movimento DESC;
  5.  
Query 2: This query find the sum of amount field 'Importo', Max and min value of Data_Movimento for each and every year from the Cessionecredito table in descending order.

Expand|Select|Wrap|Line Numbers
  1. SELECT Sum(CessioneCredito.Importo) AS SumOfImporto, CessioneCredito.Anno, Max(CessioneCredito.Data_Movimento) AS MaxOfData_Movimento, Min(CessioneCredito.Data_Movimento) AS MinOfData_Movimento
  2. FROM CessioneCredito GROUP BY CessioneCredito.Anno, CessioneCredito.ID_Agente
  3. HAVING (((CessioneCredito.ID_Agente)=[Reports]![R_StoricoCessCredAg]![ID_Agente]))
  4. ORDER BY CessioneCredito.Anno DESC , Max(CessioneCredito.Data_Movimento) DESC;
Can you guide me how to get the report in the attached format as i am using VBA and SQL query, reports to produce the output from the two different tables from MS ACCESS.

Kindly let me know if i missed any information.
Attached Images
File Type: jpg Format of new report.jpg (14.9 KB, 200 views)
Jul 2 '15 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: dkintheuk | last post by:
Hi there, I have a database with what seems like a trillion (ok, 50) interlinked queries. I want to print out, from a code subroutine, the SQL query definitions. Is this even possible? I've...
10
by: nd02tsk | last post by:
Hello I know it is possible to time isolated queries through the settting of the \timing option in psql. This makes PgSQL report the time it took to perform one operation. I would like to...
3
by: iht | last post by:
Say I have a database with types of car driven by people living in different cities. I made several queries to separate out the database according to city, then made queries to count out numbers...
3
by: nsymiakakis | last post by:
Hi everyone, I am hoping you can help me on this problem. I created 3 queries, each gives me a grand total Sum from various fields in 2 different tables. This part works great. Now I am trying to...
1
by: peter06 | last post by:
I am trying to create a database of spelling lists (multiple year levels and subjects). Each report will contain 3 columns: (e.g.) The yr 8 Internet report will have the following columns: Yr 8...
0
by: mbedford | last post by:
I'm buildling a form for tracking printer costs. This form will display data from several different tables pulled together by queries. formPrintCost will display: printer information from...
0
by: Emily F | last post by:
In the Macro section of access there is "OutputTo" action which will export a query to it's own spreadsheet in excel -What I need, is a macro (if it exists-but I think it will have to be created...
1
by: vivek samantray | last post by:
i have a script which executes several queries for n number of records.How can is set the time in that to know how much time each query took to run
2
by: eipts | last post by:
Hi all, I'm a novice to Access and programming in general so please bare with me. I have several queries from different databases in a linked table database, each of which has its own report....
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.