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

How to optemise the query having group by on two colomun

i have one table say A

Expand|Select|Wrap|Line Numbers
  1. +------------+--------------+----------------+
  2. | value1 | value 2 | value 3 |
  3. +------------+--------------+----------------+
  4. | 5 | 4adb83c1d71b | 1 |
  5. | 5 | 44fcb93589fe | 2 |
  6. | 5 | 4182b6e2100c | 1 |
  7.  
  8. | 6 | 4bfd8db46ab1 | 1 |
  9.  
  10. | 7 | 4b0f87c68808 | 1 |
  11. | 7 | 413fa4646dfe | 2 |
  12. | 7 | 4585b5671b68 | 3 |
  13. | 7 | 4486abc0ddce | 2 |
  14. | 7 | 4b01b048f07c | 5 |
  15. | 7 | 4cebb754ff21 | 2 |
  16. +------------+--------------+----------------+
Now i need an optemise query that will give number of duplicate in value 3 colomun for each value 1 colomun

mean i need a result as

+
Expand|Select|Wrap|Line Numbers
  1. ------------+--------------+----------------+
  2. | value1 | value 3 | count |
  3. +------------+--------------+----------------+
  4. | 5 | 1 | 2 |
  5. | 6 | 1 | 1 |
  6. | 7 | 2 | 3 |
  7. +------------+--------------+----------------+

mean
Expand|Select|Wrap|Line Numbers
  1. value 1(5) have value 3(1) repeate 2 time
  2. value 1(6) have value 3(1) repeate 1 time
  3. value 1(7) have value 3(2) repeate 3 time
for this i write a query but that query is not optemise so if have any better solution for query.

Expand|Select|Wrap|Line Numbers
  1. select value1,value3,count(value1) as ct 
  2. from A 
  3. where value1>0 and value1 != '' 
  4. group by value1,value3 having ct >1 limit 3;
where both the colomun value 1 and value 3 are indexed
Mar 23 '10 #1
0 1100

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

Similar topics

1
by: George | last post by:
Hi, I am trying to write a query in Oracle which I have not done before, and are having some difficulty getting my result. Please check my query and my results. select max(note.datetime),...
3
by: Robby McGehee | last post by:
I need this to work: SELECT FROM WITH (NOLOCK) where ='a' GROUP BY , HAVING COUNT () > 1 The problem is that I get an error that needs to be in the GROUP BY clause or aggregate function. if...
2
by: Paxton | last post by:
Hi, I'm trying to display the total page views per page within a given date range, but the correct SQL is seemingly beyond me. I get the correct result with a straightforward Group By and Count...
2
by: aj70000 | last post by:
This is my query select ano,max(date),a_subject from MY_TAB where table_name='xyz' and ano=877 group by a_subject,ano order by a_subject ANO max(Date) A_Subject 877 2005-01-20...
2
by: JJA | last post by:
Please advise on how to get the GROUP BY coded in an acceptable way: DECLARE @LO INT DECLARE @HI INT DECLARE @StartDate varchar(10) DECLARE @EndDate varchar(10) SELECT @StartDate =...
1
by: Shawn | last post by:
First I have to say I do not know SQL or VB very well...so if I'm able to get this to work without learning a new language then I'll be ecstatic. OK...I have a tbl of approximately 1000 lines of...
2
by: Jonathan Woods | last post by:
Hi there, I have no idea why the following TSQL does not work.Any Idea? I am using SQL 2000 Server CREATE PROCEDURE RptDailySummary2 @FromTxDate DATETIME, @ToTxDate DATETIME AS BEGIN
7
by: kooch54 | last post by:
I am trying to write a script to simply query the group members in an active directory group. I need to use LDAP to make sure I capture any global global group nestings that may occur. I already...
3
by: rmotwani | last post by:
Hi, Everybody ! I have a small problem. If I run a query with group by having two outer joins, there, group by is not working i suppose. Case: table 1 : Product master having product...
4
by: SjaakBanaan | last post by:
Hey all, I have a question that ought to be simple but has given me headaches for a while. I have a table with contact email addresses, say. T ID ContID Priority Emailaddress...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.