473,396 Members | 2,002 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,396 software developers and data experts.

Help with duplicate rows due to date/time in query

Hello,

I am trying to pull a list of sample counts by test. I only want 1 row per test result so that I can build a report in Cognos showing the rate of a particular result as a percentage of the total results.

My problem is that I am getting duplicate rows for the same result - in the example below I have 2 - 5 rows for each result instead of just 1 for each result. I have narrowed this down to being caused by the date - the date part is the same but the time parts are different so multiple rows are being pulled. I tried using trunc() but although the display now shows the same date without the time part, the duplicate rows are still being pulled.

Any help would be much appreciated!!

This is the code for the query:

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT
  2.     io.lab_id AS "LAB ID",
  3.     l.name AS "LAB NAME",
  4.     mtr.marketingtest_id AS "TEST ID",
  5.     mtl.name AS "TEST NAME",
  6.     mtr.marketingresult AS "MARKETING RESULT",
  7.     COUNT(DISTINCT mtr.sample_id) AS "NO OF SAMPLES",
  8.     TRUNC(os.statusdate) AS "STATUS DATE",
  9.     os.orderstatuscodes_id AS "ORDER STATUS",
  10.     io.redoorderid AS "REDOORDERID",
  11.     mtl.locale_id AS "LOCALE"
  12. FROM igen_sample s
  13. INNER JOIN igen_igenityorder io ON s.igenityorder_id = io.igenityorder_id
  14. INNER JOIN igen_orderstatus os ON io.igenityorder_id = os.igenityorder_id
  15. INNER JOIN igen_marketingtestresult mtr ON s.sample_id = mtr.sample_id
  16. INNER JOIN igen_lab l ON io.lab_id = l.lab_id
  17. INNER JOIN igen_marketingtestlocale mtl ON mtr.marketingtest_id = mtl.marketingtest_id
  18.  
  19. WHERE mtl.locale_id = 1
  20. AND os.orderstatuscodes_id IN (8, 9)
  21. AND mtr.marketingtest_id = 84
  22. AND os.statusdate BETWEEN '24-OCT-2011' AND '31-OCT-2011'
  23.  
  24. GROUP BY mtr.marketingtest_id, mtl.name, mtr.marketingresult, os.statusdate, os.orderstatuscodes_id, io.lab_id, l.name, io.redoorderid, mtl.locale_id
  25. ORDER BY mtl.name
  26.  
Nov 23 '11 #1
1 2375
Rabbit
12,516 Expert Mod 8TB
You need to group by the truncated date.
Nov 23 '11 #2

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

Similar topics

4
by: Russell | last post by:
I'm using MySQL 4.1.1 I've inherited a database which has some (almost) duplicate rows. The databse is like this. userID userPosition userDepartment
2
by: zaceti | last post by:
I'm new to MySQL and I am having a problem selecting the highest valued date/time for a particular day. Here is the table structure: ...
1
by: Thomas Bartkus | last post by:
If we have a date/time field and are doing frequent queries WHERE {date/time field} BETWEEN TimeA AND TimeB Does it make sense, query speed wise, to create an index on the date/time field? ...
7
by: Egor Shipovalov | last post by:
I'm implementing paging through search results using cursors. Is there a better way to know total number of rows under a cursor than running a separate COUNT(*) query? I think PostgreSQL is bound...
17
by: Lapchien | last post by:
My table has a record called date/time - filled (not surprisingly) with a date and time. I can format the date in one query field, also the time, using format in an expression. My user wants me...
3
by: MostlyH2O | last post by:
Hi Folks, I have a query that joins 3 tables. One of the tables (SalaryData) has data where there may be duplicate records with different dates. Of those duplicate records, I want the query to...
1
by: TaeHo Yoo | last post by:
I have a table that has more than 1 milion rows so practically it is impossible to remove all duplicate rows by hand. Could you help me to remove those duplicate rows at all? This table doesn't...
7
by: Jerome | last post by:
Hallo, I know a lot has already been told about date/time fields in a database but still confuses me, specif when dealing with SQLserver(Express). It seems that sqlserver only accepts the date in...
7
by: Jon Maz | last post by:
Hi, I have a MySql problem I hope someone can help me with. I'm trying to run an update on a linking table, the update is running into a Primary Key constraint violation, and in my workaround...
4
by: muzu1232004 | last post by:
Is there any query which will delete exactly one of the duplicate rows in a table and retain only one ?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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: 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
Oralloy
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,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.