473,395 Members | 1,474 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,395 software developers and data experts.

Group-by In Subselect With Union

1
I hav a query that uses a union of 16 tables to get some counts and i need to get the end result as a Group by. This is inside a sub-query that has the count(*) ans the attribute for the group-by in the select. i need to get the end result as the count for each of the group displayed as a title based on a criteria on the group attribute.
the query is something like this.. but i am not able to get the top most part ie getting to display the title based on the group-by attribute.

Expand|Select|Wrap|Line Numbers
  1. select cnt,
  2.          case
  3.          when attr = 'aaa' then cnt as Title1
  4.          when attr = 'bbb' then cnt as Title2
  5.          else cnt as Title3
  6.          end
  7. from 
  8. (select sum(cnt) , attr
  9.  from
  10. (select count(acct) as cnt, attr
  11.  from table1
  12.  wher..
  13.  union all
  14.  select count(acct), attr
  15.  from table2
  16.  where..
  17. union all
  18. ...
  19. select count(acct), attr
  20.  from table16
  21.  where..
  22. ) as ctr
  23. group by attr ) as grp
[Please use CODE tags when posting source code. Thanks! --pbmods]
Jun 22 '07 #1
0 1449

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

Similar topics

2
by: Tom Loach | last post by:
Our system administrator set up an NT server group in order to allow our users to login to our application via https to our sql server. The group appears as a User in SQL Server when you look at...
2
by: BillD | last post by:
I'm trying to derive a schema from a base schema. I want to redefine a "group" from the base schema in my derived schema in order to add more options to the "choice" aggregate (see schema1.xsd...
2
by: innesm | last post by:
Hi, Although I havent been able to find any documentation to confirm it, it looks like any change to a windows local group's membership is only reflected in the group editing UI (and the...
0
by: Melissa | last post by:
I have a grouped report with a subreport in the group footer. The report is set to start a new page for each group. All the labels for fields are in the group header and there is a subreport in the...
0
by: WALDO | last post by:
Assuming the following code: Dim strPattern As String = "(\d{3})(-)(\d{4})" Dim strMatch As String = "555-1234" Dim regExp As New RegEx(strPattern) Dim matches As MatchCollection =...
5
by: jacob.dba | last post by:
I have a table with first name, last name, SSN(social security number) and other columns. I want to assign group number according to this business logic. 1. Records with equal SSN and (similar...
1
by: JH | last post by:
Hi I am a fussy learner. Could someone explain to me why the following inconsistency exists between methods? How can it be justified if it is considered all right? There are three groups in...
3
by: Sebastian | last post by:
Hello all I have a report where I have two nested groups. I know there are only three standard options for running sum: None, Over Group and Over All. I have a MyTextBox in detail section where...
4
by: magedsql | last post by:
I am MCDBA, I like your group, and i need to join it as a member but i do NOT know How . Please help Thank You maged.
4
by: Paul.Pucciarelli | last post by:
So I have some 'groups' which 'users' can join. There is no enrollment limit on these 'groups'. How should I store the list of users enrolled in the group? I'd like to be able to quickly...
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
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
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...

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.