Is it possible to group multiple columns individually without using union?

Hi, if I have a table with a numebr of columns I want to group eg gender, nationality, age and I want to produce a summary such like:
Group Count
Male 10
Female 23
British 19
Irish 14
18 10
etc.
Or even better:
Group Count
Gender-Male 10
Gender-Female 23
Nationaility-British 19
Nationality-Irish 14
Age-18 10
Is this possible without using loads of unions? I just want to do this in the best, most efficient way as the table involved has >100 million rows.
Many thanks
Jen :)

May be this
--Test data
with t
as
select 'M' gender, 'INDIAN'  nationality, 25 age from dual union all
select 'M' gender, 'INDIAN'  nationality, 25 age from dual union all
select 'M' gender, 'INDIAN'  nationality, 30 age from dual union all
select 'M' gender, 'IRISH'   nationality, 30 age from dual union all
select 'M' gender, 'IRISH'   nationality, 40 age from dual union all
select 'F' gender, 'IRISH'   nationality, 40 age from dual union all
select 'F' gender, 'BRITISH' nationality, 50 age from dual union all
select 'F' gender, 'BRITISH' nationality, 50 age from dual union all
select 'F' gender, 'BRITISH' nationality, 45 age from dual union all
select 'F' gender, 'BRITISH' nationality, 45 age from dual
--Test Data Ends
-- Main Query
select decode(no, 1, 'Gender-', 2, 'Nationality-', 3, 'Age-') || decode(no, 1, gender, 2, nationality, 3, to_char(age)) val,
       count(*) cnt
  from t
cross join (select level no from dual connect by level <= 3)
group by no, decode(no, 1, gender, 2, nationality, 3, to_char(age))
order by no;
VAL                                                  CNT
Gender-F                                               5
Gender-M                                               5
Nationality-BRITISH                                    4
Nationality-INDIAN                                     3
Nationality-IRISH                                      3
Age-25                                                 2
Age-30                                                 2
Age-40                                                 2
Age-45                                                 2
Age-50                                                 2
10 rows selected

Similar Messages

  • Is it possible to have multiple search results page using one Search Enterprise Center site?

    Hi,
    We're using SharePoint 2013 and I'm trying to modify the search results page for one site collection. By default, it uses the search results page from the parent site which is the search center being used by default for the web application. I need to make
    sure that the site collection will only retrieve search results within the site collection (search everything has to be disabled). I found a way but I had to create another search center site to accomplish this, otherwise, it will affect the search center
    site of all other site collections on the web app.
    Now is it possible to have multiple search results page using one Search Enterprise Center site?

    Hi,
    According to your description, you want to retrieve the search results within the site collection.
    As a workaround, you can create a custom result source for the site collection and you will retrieve the search result within the site collection.
    More information about how to create result source in SharePoint 2013, please refer to :
    http://technet.microsoft.com/en-us/library/jj683115(v=office.15).aspx
    http://techmikael.blogspot.com/2013/04/limiting-search-results-in-sharepoint.html
    Best regards

  • Is there a way to send and receive SMS on multiple cellular devices without using iMessage?

    I currently own a cellular iPad mini and an iPhone 4s and would like SMS to be the same on both devices as well as my desktop.
    After many months of struggling with iMessage, I decided to turn it off entirely.  I discovered that my best friend did not receive dozens of my texts over the span of a few months (I compared our message history side by side).  Seems like it had something to do with traveling in and out of wifi zones or possibly conflicts between our two carriers, ATT and Verizon.  Regardless, I am not willing to dive into iMessage fully until this gets sorted out.  Further, SMS is the standard message format for everyone outside of the Apple sphere, and I do not feel comfortable lumping them together into one app.  If I decide to switch to Android, will all of my contacts with iPhones continue sending me iMessages?
    Thank you for your help!

    Is there a way to send and receive SMS on multiple cellular devices without using iMessage?
    Search the iTunes App Store for any 3rd party SMS apps that may be available.
    If I decide to switch to Android, will all of my contacts with iPhones continue sending me iMessages?
    Android phones don't receive iMessages, they can recieve SMS messages sent through the iOS Messages app. The app that your contacts choose to use to send you messages is completely up to them.

  • Create a Multiple-Line JButton Without Using HTML format

    I used html format for multiple-line JButton and it took a long time to load that button up (about 5 seconds more). Does anyone know how to create a multiple-line JButton without using html?
    Any suggestion or sample code will be appreciated.
    javamesser

    Hello,
    You could try using the following:
    -give your button some layout (e.g.: BoxLayout.Y_AXIS, or BorderLayout).
    -create the wrapped text in separate JLabels (one line in each label)
    -add your labels to the button
    Advantage:
    this solution does not affect the laf classes
    Disadvantage:
    focus rectangle is not calculated accurately
    Regards,
    G

  • Is there anyway to have multiple signature blocks without using an app?  Will IOS 5 have that functionality?

    Is there anyway to have multiple signature blocks without using an app?  Will IOS 5 have that function?

    "No" and "We don't know yet"

  • Is it possible to run a java program without using the command prompt?

    Hi,
    I was wondering whether it is possible to run a Java program (not an applet) without using a command line in the command prompt?
    Basically I want to run a program that will be continually running in the background and hence I don't want to have a command prompt screen loaded up as well - I just want the program to be running in the task bar.
    I know how to run the program in the task bar - but I still need to launch the program from the command prompt - is there anyway I can get a program running without having to start it from the command prompt?
    Cheers

    Or create a desktop shortcut (in Windows) or an application launcher ( in Linux GUI).

  • How to Freeze Table/Column Header "without using additional scrollbars" ?

    hi people,
    I am hoping someone can help me here. I have a large table and would like to freeze the first row. Scrolling down the table "_*using the existing scrollbars*_" in the browser while ensuring the header rows are still visible (like Excel when you freeze panes). If you scroll to the right the header rows should stay frozen and not follow.
    I know there are other threads which talk about freezing table/column header, but my requirement is to have it "without using additional scrollbar".
    Thanks in advance,
    RAKESH

    Hi,
    there is no default key for this. You will have to code your own JavaScript for this. Also, I am not sure you want the column to be selected but a field in the column for the row you are in - correct ?
    Frank

  • Is it possible to Manage Sun Fire v60 without using Red Hat?

    I've been trying to enable a console connection via an Avocent dongle connected to the serial port using these directions:
    http://download.oracle.com/docs/cd/E19088-01/v65x.srvr/817-2025-13/chap2.html
    All I've been able to view is the BIOS output, and the grub menu; I am unable to control anything.
    Is it possible to manage a Sun Fire v60x without using a Red Hat server to issue power/status commands?
    Thank you.

    Hi.
    Serial console support only text mode. So can freasing after server change mode to graphics.
    For manage server You can read:
    http://download.oracle.com/docs/cd/E19088-01/v65x.srvr/817-2025-13/chap1.html#pgfId-1014396
    Lights Out Management (LOM)
    The Intel Server Management (ISM) software is a set of applications and agents for monitoring and managing servers. The agents can act as low-level stand-alone pieces, or can be used in conjunction with full-featured integrated management suites.
    Available features include power on, power off and reset. System Event Logs (SELs) and Sensor Data Records (SDRs) can be viewed remotely.
    IMHO: It's very old server and remote control of it not user frendly.
    Regards.

  • Multiple Hit Button Without Using The Timeline

    Hello. I'm pretty much a beginner when it comes to flash. So,
    I assume there's been a post about this topic already. But, does
    anyone know how to script a code that lets you hit a button
    multiple times to execute an action without using the time line.
    For example. on
    http://www.group94.com/ website
    under menu / projects they use arrows to move the text on the y
    axis. Every time you click down on the text, it shifts upwards. I
    assume this a multiple hit action since the text shifts to? Can
    anyone help. Thanks.
    George

    Well, every action assigned to a button is executed multiple
    times when the button is hit repeatedly. I assume you mean kind of
    different actions? This could be done with a counter variable and a
    switch statement, like this:
    var count:Number = 0;
    button.onRelease = function(){
    count++;
    switch(count){
    case 1:
    // actions for 1st click
    break;
    case 2:
    break;
    case 5:
    count = 0; // reset counter
    break;
    However, in the website you linked, I suppose they don't do
    it this way, but with a more dynamic approach: Load the data (links
    and linktext) from a xml or text file, then build an array out of
    the contents and display the first entries. When the button is
    clicked, the first entry goes off, the next entry comes in. When
    the end of the array is reached, go back to entry 1 (not sure they
    do that, I didn't try it so far). So you would need a function,
    like displayNext(), that executes on every click and checks for
    itself which is the next entry to display and goes through the
    array this way.
    That's just a guess how they did it, or rather, how I would
    do it. ;)
    hth,
    blemmo

  • HT1766 iPhone 4s; Is it possible to sync apps to icloud without using the touchscreen?

    I've been using my iphone 4S with a cracked screen for over three months now (it fell on a tile floor hitting the top front corner first, 5 weeks after I got it) without any issues. Tonight I dropped it from a height of about 8 inches and the part of the face that was cracked made first contact with something that was on a table I was standing at, jamming it further into the phone. When I picked it up I noticed a small piece had also fallen out near an intersection of the cracks. The touchscreen is now completely black.
    My question: Is it possible to sync my apps to the icloud without using the iphone touchscreen? I plan I getting a new phone and had my icloud setup to sync my mail, contacts and calendars. I've been able to download all my pictures and video to my computer.

    Getting/reinstalling the apps isn't a problem. I'm only concerned with the data that is stored within them. For instance I have a mileage tracker I've been using but haven't uploaded the data from the phone to back it up anywhere. I'd like to do that before getting a new phone but I can't see what i'm doing due to the screen not working.
    The phone is actually still working and I've been able to use Siri to make calls and send texts without a working screen. The screen still accepts inputs apparently so if I could return settings to factory settings I could theoretically use another phone side by side to show me exactly where I need to touch and when to back up my applications to iClould.
    Going forward, I actually had ordered another case before my accident as my current case doesn't provide enough protection. It'd be nice if Apple actually made an iphone that didn't need such band-aids for normal usage.

  • Mild challenge -pivoting *multiple* columns per row using only SQL

    Hello All,
    I'm in the process of learning the various pivoting techniques available
    in SQL, and I am becoming more familiar with the decode,function,group-by
    technique seen in many examples on these forums. However, I've got a case
    where I need to pivot out 3 different columns for 3 rows of data where the
    value of a different column is driving whether or not those columns are pivoted.
    I know that last sentence was as clear as mud so I'll show you/provide the simple
    scripts and data, and then I'll elaborate a little more beneath.
    create table temp_timeline (
    mkt_id varchar2(10),
    event_id number(8),
    event_type varchar2(3),
    mod_due_date date,
    cur_due_date date,
    act_due_date date
    insert into temp_timeline values('DSIM6',51,'S1','NOV-13-06','NOV-13-06',NULL);
    insert into temp_timeline values('DSIM6',51,'S2','DEC-20-06','DEC-20-06',NULL);
    insert into temp_timeline values('DSIM6',51,'S3','JAN-17-07','JAN-17-07',NULL);
    insert into temp_timeline values('DSIM6',51,'S4','FEB-14-07','FEB-14-07',NULL);
    commit;
    select * from temp_timeline;
    The "normal" output (formatted with period-separated fields) is:
    DSIM6.51.S1.NOV-13-06.NOV-13-06.NULL
    DSIM6.51.S2.DEC-20-06.DEC-20-06.NULL
    DSIM6.51.S3.JAN-17-07.JAN-17-07.NULL
    DSIM6.51.S4.FEB-14-07.FEB-14-07.NULL
    The DESIRED 1-row output (formatted with period-separated fields) is:
    DSIM6.51.NOV-13-06.NOV-13-06.NULL.DEC-20-06.DEC-20-06.NULL.JAN-17-07.JAN-17-07.NULL.FEB-14-07.FEB-14-07.NULL
    So, the first 2 columns in the table have the same data, and the third column
    makes the row unique (they could all have the same/similar dates).
    If this table only consisted of the first 3 columns then many of the examples seen
    on this forum would work well (grouping by the first 2 rows and pivoting out
    the "event_type" columns containing (S1,S2,S3,S4) etc.
    But, in my case, I need to discard the event_type column and pivot out the
    3 columns of date data onto the first row (for each different event_type).
    So the 3 Dates associated with the "S2" column would go to the first row, and the
    3 dates associated with the "S3" column would also go to the first row (and so on).
    The 3 dates need to be 3 distinct columns when they are
    pivoted out (not concatenated to each other and pivoted as one column).
    Given this, I will need to pivot out a total of 12 different columns for each distinct
    (mkt_id, event_id) pair.
    For the time being I have accomplished this with a union, but am trying to expand
    my abilities with other sql methods. I've seen some very elegant solutions on this
    forum so will be interested to see what others can come up with for this solution.
    Thanks in advance for any comments you may provide.

    Just DECODE based on the event type, which will generate your 12 columns.
    SELECT mkt_id, event_id,
           MAX(DECODE(event_type, 'S1', mod_due_date, NULL)) s1_mod_due,
           MAX(DECODE(event_type, 'S1', cur_due_date, NULL)) s1_cur_due,
           MAX(DECODE(event_type, 'S1', act_due_date, NULL)) s1_act_due,
           MAX(DECODE(event_type, 'S2', mod_due_date, NULL)) s2_mod_due,
           MAX(DECODE(event_type, 'S2', cur_due_date, NULL)) s2_cur_due,
           MAX(DECODE(event_type, 'S2', act_due_date, NULL)) s2_act_due,
           MAX(DECODE(event_type, 'S3', mod_due_date, NULL)) s3_mod_due,
           MAX(DECODE(event_type, 'S3', cur_due_date, NULL)) s3_cur_due,
           MAX(DECODE(event_type, 'S3', act_due_date, NULL)) s3_act_due,
           MAX(DECODE(event_type, 'S4', mod_due_date, NULL)) s4_mod_due,
           MAX(DECODE(event_type, 'S4', cur_due_date, NULL)) s4_cur_due,
           MAX(DECODE(event_type, 'S4', act_due_date, NULL)) s4_act_due
    FROM temp_timeline
    GROUP BY mkt_id, event_idTested, because you supplied create table and insert statements, thank you.
    John

  • Inserting multiple columns into database using dbtool set

    I have  a labVIEW program that is currenly simulating voltage and a current signal using the DAQ Assistant. I'm using the database connectivity toolset. I am currently able to insert one signal into the database converted to a float(I can insert both into the same column as bianary but it needs to be stored as a usable format and in seperate columns.)
    The problem I am having is at the DB Tools Insert Data block. I have the connection, dbTable, error code, and create table boolean being passed into it. Where I am a little lost is how to set the columns I want to store the multiple signals into.
    If someone could break that part down for me that would be great. In short, I want to store voltage(channel0) and current(channel1) from the DAQ Assistant into their own respective columns in the db.
    Message Edited by DonPoulson on 07-10-2007 11:04 AM

    Don,
    This particular forum is specific to TestStand, not LabVIEW or Multifunction DAQ. You may have a better chance at responses by posting to either of those forums rather than here.
    Brandon Vasquez | Software Engineer | Integration Services | National Instruments

  • Split multiple columns into rows using XML

    Hi Forum,
    I am trying to split 2 columns that each contain values separated by semicolon into single rows. The relation between the values of the two columns is that the order in the cells corresponds to each other.
    The data looks like this:
    pk    Manufacturer                partnumber
    1     Man1; Man2;Man3      PN1;PN2;PN3
    2     Man4; Man2;Man5      PN4;PN5;PN6
    The result should be:
    pk    Manufacturer     partnumber
    1       Man1                   PN1
    1       Man2                   PN2
    1       Man3                   PN3
    2       Man4                   PN4
    2       Man2                   PN5
    2       Man5                   PN6
    I am not sure how to format the XML to get a useful Basis for XML.value or XML.query
    Any ideas?
    TIA
    Alex

    Hi,
    Try like this ,
    DECLARE @tmp TABLE (pk INT,Manufacturer NVARCHAR(50),partnumber NVARCHAR(50))
    INSERT @tmp SELECT 1,'Man1; Man2;Man3','PN1;PN2;PN3'
    INSERT @tmp SELECT 2,'Man4; Man2;Man5','PN4;PN5;PN6'
    SELECT * FROM @tmp
    SELECT tmp2.pk pk,Manufacturer,partnumber FROM (
    SELECT ROW_NUMBER()OVER(ORDER BY tmp1.pk) RN,* FROM (
    SELECT pk,
    LTRIM(i.value('.','varchar(100)')) Manufacturer
    FROM ( SELECT pk, Manufacturer,
    CONVERT(XML,'<r><n>'
    + REPLACE(Manufacturer,';', '</n><n>') + '</n></r>') AS X
    FROM @Tmp) Spt
    CROSS APPLY Spt.X.nodes('//*[text()]') x(i)
    ) tmp1 ) tmp2
    JOIN
    (SELECT ROW_NUMBER()OVER(ORDER BY pk) RN,* FROM (
    SELECT pk,
    j.value('.','varchar(100)') partnumber
    FROM ( SELECT pk, partnumber,
    CONVERT(XML,'<r><n>'
    + REPLACE(partnumber,';', '</n><n>') + '</n></r>') AS Y
    FROM @Tmp) Spt
    CROSS APPLY Spt.Y.nodes('//*[text()]') y(j)) tmp2 ) tmp3 ON tmp3.RN = tmp2.RN
    sathya - www.allaboutmssql.com ** Mark as answered if my post solved your problem and Vote as helpful if my post was useful **.

  • Is it possible to string multiple sound files together using code?

    Say I recorded and imported sound files of my voice saying "Two",  "Four", "Equals", and "Plus"
    Would it be possible to have Flash on click string together those sound files like a string so that the user would hear:
    "Two...Plus...Two...Equals...Four."

    yes, the sound class and its related classes have all the methods and events you need for that.  you would, for example, use the sound class and the soundchannel's soundComplete event to string sounds together starting one after a previous finished.

  • Change multiple column to rows using unpivot or pivot

    is there any way I could use pivot or unpivot to get the result show in the graph? From the top table structure to the lower table structure. I could do activity hours and desc separately using unpivot but do not know how to join them together. 

    Looks like a pivot isn't the best bet, try this:
    DECLARE @ActivityReport TABLE ([Employee_ID] [int] NULL, [Week] nvarchar(50) NULL, [Hours_Admin] [float] NULL, [Desc_Admin] [nvarchar](200) NULL, [Hours_HelpDesk] [float] NULL, [Desc_HelpDesk] [nvarchar](200) NULL, [Hours_Support] [float] NULL, [Desc_Support] [nvarchar](200) NULL)
    insert into @ActivityReport VALUES (1, 'week1', 5, 'desc', 6, 'desc', 9, 'desc'), (1, 'week2', 5, 'desc1', 6, 'desc1', 9, 'desc1'), (2, 'week1', 5, 'desc', 6, 'desc', 9, 'desc'), (2, 'week2', 5, 'desc2', 6, 'desc2', 9, 'desc2')
    SELECT employee_ID, week, hours_admin AS activityHours, 'admin_hours' AS activity_type
    FROM @ActivityReport
    UNION ALL
    SELECT employee_ID, week, hours_helpdesk AS activityHours, 'helpdesk_hours' AS activity_type
    FROM @ActivityReport
    UNION ALL
    SELECT employee_ID, week, hours_support AS activityHours, 'support_hours' AS activity_type
    FROM @ActivityReport
    ORDER BY Employee_ID, week
    Don't forget to mark helpful posts, and answers. It helps others to find relevant posts to the same question.

Maybe you are looking for

  • No sound after importing mpeg from imovie

    Hello, i'm new to IMovie and i have the problem that all my video files made with my photocamera loose the sound when i import them into Imovie. the FAQ's tell me it is because they are in mpef-muxed structure. Can anybody help me with the solution o

  • New MBP wireless problems

    Hi all, im sure you are all sick of reading the same problems time after time. Anyway, mine is as follows.. Got my new Mac around 1 month ago, love it. My old 17 mbp always sat at my desk and i usually run a wired connection to the internet. Now afte

  • Problems w/ KT3 Ultra2 w/R

    I think the best thing to do it's to explain the problem from the beginning. A couple of months ago I bought my computer by components and put it togheter myself. Everything was fine, but there was a problem. Back then, my mobo was an ABIT KX7333R an

  • ADC and DVI  (GeForce FX 5200)

    Hello, I need some help! I have been offered a G5 1,8Ghz PowerMac with a GeForce FX 5200. Just a while ago, I bought an LCD Monitor (22``) with only one D-SUB socket (analog). Do I have the chance to run this monitor with the installed GeForce ??? Ho

  • SOMETHING IS WRONG, I SEND A FILE TO TRASH AND DOES NOT APPEAR IN TRASH, THE TRASH IS EMPTY

    SOMETHING IS WRONG, I SEND A FILE TO TRASH AND DOES NOT APPEAR IN TRASH, THE TRASH IS EMPTY