473,473 Members | 1,857 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

"group by" by excluding prefix

Suppose there is a table containing these recodes.

country
-------
CON_CHN
CON_JAP
JAP
CON_CHN

When I use the following sql:
select country, count(*) as num from table group by country

the normal result will be:
country num
---------------
CON_CHN 2
CON_JAP 1
JAP 1

However, my desired result is as follows:
country num
-----------------
CON_CHN 2
CON_JAP 2

How can I re-write my SQL? Or any other methods to do that?

Apr 12 '06 #1
2 2154
MC
Is the length of the string (prefix or sufix) fixed? Can the string be
something like CON_CANA ? Also, it would help if you provided sample
scripts....
MC
"littlebeam" <cy*******@gmail.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
Suppose there is a table containing these recodes.

country
-------
CON_CHN
CON_JAP
JAP
CON_CHN

When I use the following sql:
select country, count(*) as num from table group by country

the normal result will be:
country num
---------------
CON_CHN 2
CON_JAP 1
JAP 1

However, my desired result is as follows:
country num
-----------------
CON_CHN 2
CON_JAP 2

How can I re-write my SQL? Or any other methods to do that?

Apr 12 '06 #2
If your prefix is always "CON_" then this should work

SELECT Replace(country, 'CON_',''), COUNT(Replace(country, 'CON_',''))
from myTable
Group by Replace(country, 'CON_','')

Markus

Apr 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tamer Higazi | last post by:
Hi! I have problems creating joins between tables and to limit rows for a specified clolumn. I have 2 tables! employees departments I face the problems with the GROUP BY clause and i don't...
2
by: mark | last post by:
How can I use "Group By" or a formula to group my query results in 1-year periods from a given date, e.g. 3 groups: 1 Sept 2001 - 1 Sept 2002 1 Sept 2002 - 1 Sept 2003 1 Sept 2003 - 1 Sept 2004 ...
0
by: TaeHo Yoo | last post by:
After running my code, group tree(the left section of the report) changes but not the content in the report. My code is ---------------------------------------------------------- Private Sub...
4
by: Phill W. | last post by:
Is there anything amiss with the newsgroup microsoft.public.dotnet.vb.general ?? From where I'm sitting, it's /completely/ dried up - only four posts in as many days. Did I miss the mass...
5
by: Dave Smithz | last post by:
Hi there, Been working on an evolving DB program for a while now. Suddenly I have come across a situation where I need to update a table based on a group by query. For example, I have a table...
1
by: ASF | last post by:
Is it possible to create a crystal report graph in which a user selects some parameters---a date range for instance--- AND the table field that they wish to "Group By" then hits the submit button...
1
by: Thomas Qi | last post by:
There is a basic sql below: SELECT CTEnr AS ID, TimeStamp, DatagramSize, Source AS LocalIP, Destination AS RemoteIP, Protocol, Messages, SourcePort AS LocalPort, DestPort AS RemotePort FROM...
2
by: nico3334 | last post by:
Hi, I have a SQL table that has data like this: Title Month Info 1 ---- 7 ---- 100 1 ---- 7 ---- 100 1 ---- 8 ...
2
by: BrightFuture | last post by:
I'm fairly new to detailed data analysis. A lot of my queries end up using the Group By function, but other than knowing when to use it, I don't understand how it works. All I'm doing is hitting...
0
marktang
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,...
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...
1
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.