I have a table t1 with two columns : c11 varchar(32) , c22 varchar(32)
The data in the table is :
'11', 'aa01'
and on upto
'11', 'aa50' : total 50 entries
'22', 'b01'
'22', b'02'
'22', b'03'
'33', 'c01' to '33', 'c40' : total 40 entries
'44', 'b02'
'44', 'd01'
'44', 'd01'
'44', 'd01'
How can write a query which will bunch together values of c11
with rows 5, and then bunch together values of c11 with
rows < 6, and add them up.
My output should be :
'11' 50
'33' 40
'others' 7 (3 rows for '22' and 4 for '44' are bunched
together
as the # of rows < 6, and added. 3+4 = 7) 1 2044 dn*****@gmail.c om (dn*****@gmail. com) writes:
I have a table t1 with two columns : c11 varchar(32) , c22 varchar(32)
The data in the table is :
'11', 'aa01'
and on upto
'11', 'aa50' : total 50 entries
'22', 'b01'
'22', b'02'
'22', b'03'
'33', 'c01' to '33', 'c40' : total 40 entries
'44', 'b02'
'44', 'd01'
'44', 'd01'
'44', 'd01'
How can write a query which will bunch together values of c11
with rows 5, and then bunch together values of c11 with
rows < 6, and add them up.
My output should be :
'11' 50
'33' 40
'others' 7 (3 rows for '22' and 4 for '44' are bunched
together
as the # of rows < 6, and added. 3+4 = 7)
Here is a query that works in the Northwind database:
SELECT CustomerID, SUM(cnt) AS cnt
FROM (SELECT CASE WHEN cnt 7
THEN CustomerID
ELSE 'Others'
END AS CustomerID, cnt
FROM (SELECT CustomerID, COUNT(*) AS cnt
FROM Orders
GROUP BY CustomerID) AS a) AS b
GROUP BY CustomerID
ORDER BY CASE CustomerID WHEN 'Others' THEN 'ZZZZZZ' END,
cnt DESC
The query includes two derived tables. A derived is a virtual temp
table within the query so to speak. It's an entirely logical concept,
and the optimizer often recasts computation order, often resulting in
very efficient plans.
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se
Books Online for SQL Server 2005 at http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinf...ons/books.mspx This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jim Patterson |
last post by:
I am trying to compile php with sablotron and I get this error message
=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
xslt_set_object function
=====================================================================
make: *** Error 1
|
by: AJ |
last post by:
Hi,
I have a view in which I have 3 cols...(pno,ptno,diff)..diff is the
difference in time in minutes.I want to calculate Median(diff) group
by pno,ptno...using a sql query for SQL server...
Any help is greatly appreciated..
Thanks
|
by: dolbz.cardiff |
last post by:
Hi,
I would have asked this in the MRTG newsgroups but they all appear to
be dead. Sorry if this is the wrong place for the question.
I have been looking at the MRTG
(http://people.ee.ethz.ch/~oetiker/webtools/mrtg/) source code in order
to gain an understanding of how it works. Everything was going fine
until I ran into the 'diff' function. Could anyone provide a brief
overview of what it is actually doing. I am fairly new to C so...
|
by: Ching-Lung |
last post by:
Hi all,
I try to create a tool to check the delta (diff) of 2
binaries and create the delta binary. I use binary
formatter (serialization) to create the delta binary. It
works fine but the delta binary is pretty huge in size. I
have 1 byte file and 2 bytes file, the delta should be 1
byte but somehow it turns out to be 249 bytes using binary
formatter. I guess serialization has some other things
added to the delta file.
|
by: Berrucho |
last post by:
Please Help!
I recently posted this same issue but got no answer... please help
Using VB.NET, IIS5, W2K Adv SP3 all patches, .net 1.0, VS.NET 2002
Using forms authentication, persistent cookie = false
Recently my asp.net app is returning wrong data to users. Users frequently
get data that should only be seen by other user.
| |
by: Andreas Kasparek |
last post by:
Hola!
I'm preparing my master thesis about a XML Merge Tool implementation and was
wondering if there is any open standard for XML diff regarding topics like:
- is a diff result computed on the ordered or unordered xml node tree of
the compared documents?
- what identifiers/criteria should be used by default to match elements of
the same type in different documents?
- should a diff tool consider move operations or only insert/delete
|
by: BarbaraB |
last post by:
Is there anyway of returning the value of an option group (in access 2003) back to what it was before any entry was made? I frequenty find people are wishing to remove there answer but with an option group it seems as if once you have made a choice, although you can change the choice, there is no way of returning it to its original state of having nothing selected. I know I can do this with a combo box by simply deleting the entry but I was...
|
by: Aaron Gray |
last post by:
Hi,
I am working on an HTML WYSISYG Wiki and need to display a diff page like
WikiPedia does if two people edit a file at the same time to give the second
user the diff. Basically with additions in red and deletions in red strike
though.
There seem to be several in Perl and Python and many diff programs which all
seem to be line based and work on text written in PHP.
|
by: annemariearmour |
last post by:
I am using Crystal reports version 11.2 to create reports. The data source is SQL Server, and I am using views rather than reporting directly from tables.
I apply selection criteria to the incoming records at record level and at group level. For example, I may select all bill lines with a receipt date within a certain date range. This results in a list of bill lines within that date range.
The records are grouped and values on the records...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 we have to send another system
| |