I have a table that has job data, Account_Num, Work_Order_Num, Date, Short_Desc, TechID, QCID, QCPassFail.
In this table there may be multiple records with the same Account_Num and Work_Order_Num, however when it comes time to check the QCPassFail, I need to only count 1 for each unique Account_Num/Work_Order_Num pair.
My problem comes in that I need more than just those 2 fields for reporting purposes so a SELECT DISTINCT on those two fields only won't work.
I've tried using a subquery with WHERE x IN, and I've had no luck trying to use an inner join using the same table.
6 1561
So for the accounts that have more than 1 record, what are the rules that you want to apply in order to work out which one of them you want the query to return.
Or are you after something like this -
SELECT a.Account_Num, Ctn_Account,
-
a.Work_Order_Num, Cnt_Order,
-
Date, Short_Desc, TechID, QCID, QCPassFail
-
FROM YourTable a
-
left join
-
( SELECT Account_Num, Work_Order_Num,
-
count(Account_Num) as Ctn_Account,
-
count(Work_Order_Num) as Cnt_Order
-
FROM YourTable
-
) b on a.Account_Num=b.Account_Num
-
and a.Work_Order_Num=b.Work_Order_Num
-
- Account_Num Work_Order_Num Schedule_Date Short_Desc TechID QCID QCPassFail
-
20661406 25853100 2007-10-12 VIDEO DISC 73002 73011 1
-
20661406 25853100 2007-10-12 CHSI DISC 73002 73011 1
For the purposes of this report, I only need 1 of these records, which one, is irrelevant.
What kind of report are you generating? If just a count or summary, you don't need the entire record, which could be easier to be implemented in a query.
-- CK
What kind of report are you generating? If just a count or summary, you don't need the entire record, which could be easier to be implemented in a query.
-- CK
I need all the information shown in the records (the actual records have a lot more information) This information is pulled into an excel spreadsheet for a detailed report (the count is done by formula in excel).
Not sure if this suits all of your data but it works for the data you provide -
SELECT Account_Num,
-
Work_Order_Num,
-
count(Account_Num) as Account_Num,
-
count(Work_Order_Num as Work_Order_Num,
-
Schedule_Date,
-
first(Short_Desc) as Short_Desc,
-
TechID,
-
QCID,
-
QCPassFail
-
FROM YourTable
-
GROUP BY Account_Num,Work_Order_Num,Schedule_Date,TechID,QCID,QCPassFail
-
Or this may suit better -
SELECT Account_Num,
-
Work_Order_Num,
-
count(Account_Num) as Account_Num,
-
count(Work_Order_Num as Work_Order_Num,
-
first(Schedule_Date) as Schedule_Date,
-
first(Short_Desc) as Short_Desc,
-
first(TechID) as TechID,
-
first(QCID) as QCID,
-
first(QCPassFail) as QCPassFail
-
FROM YourTable
-
GROUP BY Account_Num,Work_Order_Num
-
Working solution: - SELECT DISTINCT Account_Num,
-
-
Work_Order_Num,
-
-
Schedule_Date,
-
-
Assigned_Installer,
-
-
MIN(Short_Description) as Short_Desc,
-
-
QCID,
-
-
QCPassFail
-
-
FROM QCData
-
-
WHERE QCPassFail IS NOT NULL AND Schedule_Date >= '3/1/2008' AND Schedule_Date <= '3/31/2008'
-
-
GROUP BY Schedule_Date, Account_Num, Work_Order_Num, Assigned_Installer, QCID, QCPassFail
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Santosh |
last post by:
Since I just started my new work, I have inherited a MS Access
database which has nearly 13000 records in a single table. Now, my
mandate is to clean the database and maybe split the table into...
|
by: mark |
last post by:
Please excuse this blatant attempt at advertising. I hope you find this
software both interesting and useful.
http://www.caddproductivity.com/dataswap.htm
Data Swap
The Data Swap program...
|
by: |
last post by:
Hello,
Does anyone have an idea on how I can filter the data in the gridview
control that was returned by an sql query?
I have a gridview that works fine when I populate it with data. Now I...
|
by: sdowney717 |
last post by:
from this, circdate being a datetime field:
SQLQuery = "select distinct circdate from circdata order by circdate"
I need the distinct date portion excluding the time part.
this has come about...
|
by: rAinDeEr |
last post by:
Hi,
I have a web application with a table to store terms and
conditions of a Company.
This may some times run into many pages and some times it may be just a
few sentences. It is a character...
|
by: syvman |
last post by:
Hi all... I have a quick question, if anyone knows the answer. I've
built a query which looks at a set of records in a table (tblFilename)
and I've set it up so that it displays the following...
|
by: Rajasuds |
last post by:
I have a question in MS Access
I have two tables
MASTER with Fields 1, Field 2, Field 3
TRANS with Field1, Field 2, Field,10
I need to set up a look up condition where, I need !Field 2 to...
|
by: Techhead |
last post by:
I need to run a SELECT DISTINCT query across
multiple fields, but I need to add another field that is NON-DISTINCT
to my record set.
Here is my query:
SELECT DISTINCT lastname, firstname,...
|
by: DeanL |
last post by:
Hi all,
I'm trying to set up a query that runs from a command button on a form
(simple enough so far), what I want the query to do is take values
from the fields on the form (seven fields in...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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: 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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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,...
| |