Hi all,
Something which I feel would have been relatively easy seems to not be coming out the way I wish.
I am using the following sql to query how many nonconformances have occured by month and at what cost. - SELECT Count(tbllog.NCC_ID) AS NCCS, Sum(tblCosts.CostFig) AS SumOfCostFig, Format([DteOccur],"mmmm" & "yyyy") AS TimeLine
-
FROM tbllog LEFT JOIN tblCosts ON tbllog.NCC_ID = tblCosts.NCC_ID
-
GROUP BY Format([DteOccur],"mmmm" & "yyyy")
-
ORDER BY Format([DteOccur],"mmmm" & "yyyy");
-
I am trying to order the dates by oldest to newest. However I get the following output (I threw in feb1986 just to prove to myself it was wrong): - NCCS SumOfCostFig TimeLine
-
5 £33,234.00 August2010
-
10 February1986
-
1 £30,000.00 February2010
-
4 £3,790.00 July2010
-
7 £985.00 June2010
-
1 £50,000.00 March2010
-
2 £5,700.00 May2010
As you can see the timeline is not in the correct order. I can see the sql doesnt look quite right as there isn't an actual order to say go ascending/descending so I assume it is how I have tried to format DteOccur which is a Short Date to get it to month/year.
Anyone able to clarify how this should be done correctly.
Thanks,
Chris
1 1729
I have got further with this and now producing: - SumOfCostFig Dateofevent CountOfNCC_ID
-
£30,000.00 February 2010 1
-
£50,000.00 March 2010 1
-
£5,700.00 May 2010 2
-
£985.00 June 2010 7
-
£3,790.00 July 2010 4
-
£33,234.00 August 2010 5
However if I remove the "Count" on NCC_ID I get the true data: - SumOfCostFig Dateofevent NCC_ID
-
£30,000.00 February 2010 585
-
£50,000.00 March 2010 586
-
£5,700.00 May 2010 472
-
£125.00 June 2010 522
-
£400.00 June 2010 524
-
£80.00 June 2010 525
-
£40.00 June 2010 536
-
£340.00 June 2010 580
-
£1,260.00 July 2010 521
-
£2,000.00 July 2010 578
-
£30.00 July 2010 579
-
£500.00 July 2010 602
-
August 2010 650
-
August 2010 656
-
£33,234.00 August 2010 657
-
August 2010 670
As you can see in June shows 5 records to be added to the NCC ID Count. However 7 are shown in the first table when I do a Count.
I think this is because for some reason the count is counting the underlying cost fig table data. Where each ID number has multiple costs assigned to it. My query has summated these costs and grouped by them. However the query Count on NCC ID looks to be counting the ID values in the cost table.
How do I make my query count UNIQUE/DISTINCT as this will then only count the ID once.
Current sql: - SELECT Sum(tblCosts.CostFig) AS SumOfCostFig, Format([DteOccur],"mmmm yyyy") AS Dateofevent, Count(tbllog.NCC_ID) AS Test
-
FROM tbllog LEFT JOIN tblCosts ON tbllog.NCC_ID = tblCosts.NCC_ID
-
GROUP BY Format([DteOccur],"mmmm yyyy"), Month([DteOccur])
-
ORDER BY Month([DteOccur]);
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: vnl |
last post by:
I'm trying to run a SQL query but can't find any records when trying to
select a certain date. Here's the sql:
SELECT field 1, field2, date_and_time,
FROM table1
WHERE date_and_time =...
|
by: Dani |
last post by:
Hi,
I´m no superuser when it comes to MS Access. So I use MS Query to pull
out info from an SQL database to Excel.
I have a tabel containing different "titles" or "colums".
One contains a date....
|
by: Julie Wardlow |
last post by:
Help!
I am calculating a future date using the DateAdd function in a query (the
calculation also involves an IIf statement), and have managed to get this
formula to produce the required result....
|
by: schmud |
last post by:
i'm having trouble correctly sorting dates in my dataview. It will sort the column but it just sorts according to the month number. I need to display the data on my companies site with the most...
|
by: Scotter |
last post by:
Hi, I've been trying to make a report that will show the deliverys to be made between 2 dates, or the deliverys to be made after a certian date, or the deliveries that were made before a certian...
|
by: Sandboxer |
last post by:
I want to be able to program Access to provide for me, by individual day, what my contract obligations are to my customers. Will Access recognize all the individual days in between a date range...
|
by: nhkam |
last post by:
I am using MS Access 2007
I have a transaction table which holds all records with posting date on each of them. I used a make table query to find out the max date hold in the transaction table and...
|
by: Martin Ruprecht |
last post by:
Hi,
I do have a big problem:
We are creating a reporting tool for logistic solutions using Crystal Reports.
I actually am programming a history report. There are millions of lines in the...
|
by: Donna Wiley |
last post by:
I have a date field that could be formatted m/d/yyyy, mm/d/yyyy, m/dd/yyyy, or mm/dd/yyyy. I need to be able to enter a start date and an end date in a parameter query, i.e. Between (date) and...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
| |