Xquery grouping question

I have an XML database which I need to query. Below is a portion of the database.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<DVDStore>
<DVDTitles>
     <DVDTitle>
          <title>A. I. Artificial Intelligence </title>
          <date>2002-03-05</date>
          <studio>
               <name>Universal studios</name>
          </studio>
          <rated>PG-13</rated>
          <region_code>1</region_code>
          <directors>
               <name>Steven Spielberg</name>
          </directors>
          <starring>
               <name>Haley Joel Osment</name>
               <name>Jude Law</name>
          </starring>
          <reviews>
               <review>
                    <reviewer>
                         <name>Andrew</name>
                    </reviewer>
                    <review_date>2002-01-31</review_date>
                    <location>San Diego, CA</location>
                    <rating>5</rating>
                    <comment>Amazing, visually stunning and thought-inspiring</comment>
               </review>
####I can retrieve and calculate distinct titles with their average rating.
<studios>
for $s in distinct-values(//studio/name)
let $title := //DVDTitles/DVDTitle
order by $s
return <studio><name>{$s}</name><DVDTitles>
for $t in $title
where $s=$t//studio
order by $t/title
return $t/title
}</DVDTitles></studio>
</studios>
####I can retrieve and list each title grouped by their studios.
<studios>
for $s in distinct-values(//studio/name)
let $title := //DVDTitles/DVDTitle
order by $s
return <studio><name>{$s}</name><DVDTitles>
for $t in $title
where $s=$t//studio
order by $t/title
return $t/title
}</DVDTitles></studio>
</studios>
I can't seem to get the distinct titles with their average ratings group by their studios.
Can anyone help?

You've given twice the same query...
Do you really need to check for distinct titles in the database? Aren't they supposed to be unique?
How about :
let $d := doc("c:\temp\dvdstore.xml")
return
<studios>
  for $s in distinct-values($d//studio/name)
  order by $s
  return <studio>
     <name>{$s}</name>
     <titles>
         for $t in $d//DVDTitle
       where $t/studio/name = $s
         return <title>
          <name>{$t/title/text()}</name>
          <avg-rating>{avg($t/reviews/review/rating)}</avg-rating>
              </title>
     </titles>
         </studio>
</studios>If your processor supports XQuery 3.0 then you can use a group-by expression :
let $d := doc("c:\temp\dvdstore.xml")
return
<studios>
  for $t in $d//DVDTitle
  let $s := $t/studio/name
  let $title := <title>
            <name>{$t/title/text()}</name>
                 <avg-rating>{avg($t/reviews/review/rating)}</avg-rating>
                </title>
  group by $s
  order by $s
  return <studio>
     <name>{$s/text()}</name>
     <titles>{$title}</titles>
         </studio>
</studios>

Similar Messages

  • Multiple Artwork Covers Issue & Grouping Question

    My favorite band is The Smashing Pumpkins. Their latest album +Teargarden by Kaleidyscope+ is being released one song at a time online for free and in 11 different limited EPs that will compose the whole album. My problem here is that there a two artwork covers, one for the entire album and a second for each EP (only one EP has been released, the first song for the second EP is out). The first EP displays with the EP cover but the one song from the second EP only displays the overall album cover. How do I get my Classic to display only one cover instead of picking randomly (as it seems)?
    The following question deals with the same album. I want to group the EPs that are to be released in the future so that on my Classic I see only one big album instead of multiple EPs. Unlike their Machina II these EPs have subtitles for them. What I am wanting is one album cover to display (the overall album artwork), the name to display as +Teargarden by Kaleidyscope+ not +Teargarden by Kaleidyscope Vol. 1: Songs for a Sailor+ which is the name of the first EP in the album section of my Classic. Is all of this possible?

    Just lke dropping support for 5 year old Tiger OS in iTunes while continuing support for 10 year old XP is an enhancement.  Just like making the Library directory invisible in Lion is an enhancement.  Just like dropping support for PPC generation applications in Lion is an enhancement.  Just like, etc.
    https://discussions.apple.com/thread/3496844?start=0&tstart=0
    https://discussions.apple.com/thread/3650998?start=0&tstart=0
    https://discussions.apple.com/thread/3529592?start=0&tstart=0
    https://discussions.apple.com/thread/3503860?start=0&tstart=0
    https://discussions.apple.com/thread/3498690
    More with a web search using:
    site:discussions.apple.com itunes artwork arrow

  • Authenticated Users Group Question

    I have a quick question regarding the Authenticated Users "group". I used to be a systems administrator, but I'm a bit rusty since I've been a software developer for the last 10 years. A conflict with data center operations (DCO) group
    at work lead me to get another opinion.
    The question is this... is the authenticated users group a domain-level group or is there a local authenticated users group that would allow only users authenticated locally? We have a share that permits the authenticated users group access.
    My opinion is that all domain users who have authenticated successfully have access to this share. The DCO group is telling me that this is the local (to the server containing the share of course) authenticated users group only.
    Is there such a thing as a local-only authenticated users group? To me this doesn't even make sense, but I could very well be wrong.
    Nathon Dalton
    Sr. Software Engineer
    Blog: http://nathondalton.wordpress.com

    I apologize. I don't think I explained myself correctly. Let's consider the following...
    SERVER: SERVER1
    DOMAIN: DOMAIN1
    SHARE: \\SERVER1\SHARE1
    SHARE PERMISSIONS: Authenticated Users - Full Control
    Given the above information, is it possible that the Authenticated Users group will allow ONLY users that are defined on SERVER1 to access \\SERVER1\SHARE1?
    My understanding is that's not possible. There's one defined Authenticated Users group and that represents ALL users that are authenticated against DOMAIN1, whether added to local groups, shares, etc.
    What I'm being told however is that SHARE1 having Authenticated Users assigned is okay since only those user accounts defined on SERVER1 will be able to access it. All the users in the domain will NOT be able to access it. I think this is bogus. Am I wrong?
    Nathon Dalton
    Sr. Lead Developer
    Blog: http://www.nathondalton.com

  • A few SQL related protection group Questions - DPM 2012 R2

    Hi - Here is my environment: DPM 2012 R2 backing up SQL 2012 DBs. Some of the DBs are simple recovery model, some are full recovery model in the same protection group.
    1) Regarding the fact that DPM only looks to the recovery model when the DB is first added to the protection group, if I ever changed the recovery model in the future, would stepping through the "Modify Protection Group" wizard without changing
    anything be the solution for DPM not changing its methodology on the backing up or not backing up the log files? Or would I have to remove the affected databases from the protection group and add them back in?
    2) I have disk protection configured for 30 Days, sync every 15 minutes, and application recovery points once per day. Online protection is configured for 90 Days. Does this mean my disk consumption on the DPM side for full model databases will be the full
    size of the databases, plus the amount of changes observed over 30 days? OR does it mean it will keep 30 full copies of the DB? I am fairly sure the former.
    3) If I do decide to reduce the retention range on the disk side of this protection group to say 14 days, are there any specific issues with changing that after the PG has been working for some time?
    4) My former backup solution had an option to run consistency checks after every SQL job. Is that still considered best practice? Would the "Run a daily consistency check" be a better choice than the "Only run if a replica becomes inconsistent"
    option that I currently have in place? Would there be any ramifications to enabling this now after this PG has been in place for some time?
    Thanks very much!

    Hi
    Q1) Regarding the fact that DPM only looks to the recovery model when the DB is first added to the protection group, if I ever changed the recovery model in the future, would stepping through the "Modify Protection Group" wizard without changing
    anything be the solution for DPM not changing its methodology on the backing up or not backing up the log files? Or would I have to remove the affected databases from the protection group and add them back in?
    A1)
    Changing the Recovery Model of a Database
    To change the recovery model of a protected database to the simple recovery model
    Stop protection of the database, selecting the retain replica option.
    Change the recovery model on the SQL Server database.
    Add the database to a protection group.
    Q2) I have disk protection configured for 30 Days, sync every 15 minutes, and application recovery points once per day. Online protection is configured for 90 Days. Does this mean my disk consumption on the DPM side for full model databases will be the full
    size of the databases, plus the amount of changes observed over 30 days? OR does it mean it will keep 30 full copies of the DB? I am fairly sure the former.
    A2) Your disk consumption on the DPM will be for size of model databases plus the amount of changes observed over 30 days.
    Q3) If I do decide to reduce the retention range on the disk side of this protection group to say 14 days, are there any specific issues with changing that after the PG has been working for some time?
    A4) Not really, but to gain back the potential extra space allocated for the original 30 day retention - you can try shrinking the recovery point volume once the retention range is reduced and the older recovery points are pruned.  I would wait until
    after midnight to be sure the old RP's are deleted, then try to shrink.
    Q4) My former backup solution had an option to run consistency checks after every SQL job. Is that still considered best practice? Would the "Run a daily consistency check" be a better choice than the "Only run if a replica becomes inconsistent"
    option that I currently have in place? Would there be any ramifications to enabling this now after this PG has been in place for some time?
    A4)  A consistency check will only run if DPM detects the replica is inconsistent.  Even if you have the option selected to run nightly, if the replica is already consistent a consistency check will be skipped.
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Regards, Mike J. [MSFT]
    This posting is provided "AS IS" with no warranties, and confers no rights.

  • Hierarchical Tree Data Query/Record Group Question

    I need help with Hierarchical Forms right now. I'm currently trying to implement a hierarchical tree to display the different items in different categories. I have been reading up on it for the past few days, and i do not understand a few things.
    What is the difference between a data query and record group? they seem the same to me.
    How does the XX = prior XXX work? i understand that this is what connects the parent to the child.
    How do you determine what depth the node is? its done in the record group/data query, but how do i decide what level it is dynamically?
    Thanks a lot in advance!

    Thanks! I am unable to create a table specifically for the tree because i am using tables that have been ported live and are in use. My question about levels is how do I know which depth the node is. For example, i have a category called Information Technology and a category item called Business Informatics. I want to know how to decide that the Category(information technology) is on level 1 and the Item(business informatics) is on level 2.
    Information Technology
    |_
    Business Informatics
    And i do know how the Connect By XX = prior XXX works in the data query/record group.
    Thanks for your help!

  • Address Book Smart Group question

    Hello all,
    I want to create a Smart Group in Address Book that compiles people according to their job title.
    For example a group of everyone whose job title is 'Manager', i.e. Job Title contains Manager. But for some reason Job Title is not in the list of options when creating a Smart Group.
    Is there a way to make it work?
    Also, (a question for all the Snow Leopard users) is the option for Job Title there in OSX 10.6?
    I'm using Tiger 10.4.11.
    Thanks all.

    There is no such field for Job Title by default. If you select the Add Field item from the Card menu you can add that field to a card. However, I do not see Job Title as a search field for a Smart Group. I assume this is a bug which you can report here: Feedback.

  • PCNS Inclusion Group question

    Hi,
    To ensure PCNS works correctly, I assume you have to be part of the Inclusion Group at the time of your password change?
    The scenario I am thinking of is where FIM manages the membership of the Inclusion Group...and the user changes their password before a FIM export updates their Group membership...I guess PCNS won't magically start working once they enter the correct Inclusion
    Group?
    just some wishful thinking ;)

    Yes, you understand it correctly - password would be changed only in the user's domain and would not be propagated to other directories.
    If you found my post helpful, please give it a Helpful vote. If it answered your question, remember to mark it as an Answer.

  • Advanced filtering/grouping question (pivot-table?)

    Ahoy. I have come across a few flies in the final varnish of an image database I'm working on. I don't yet know the best way to ask the question. I think what I am looking for is some kind of pivot-table like grouping capability. I think I could do this with nest-able Smart Albums -- but you can't nest Smart Albums in Aperture. (Journler, for those who used it, had, imho, a brilliant implementation of nest-able filters.)
    Let me give what should be able to serve as a good generic example: a Library of dog images. These are organized into Projects based on shoots. The images are keyworded with the dogs' breeds, their type, their coat type and color, their individual names (when known), and other "normal" dog characteristics (gender, age when known, etc.). There are also some special keywords, such as a set for expressions (Relaxed, Angry, Teeth Bared, Questioning, Attentive), and, where needed, details of ailments (Sore, Rash, Teeth, Gums, Wound).
    I have set up Smart Albums to show many of these, e.g.:
    . Spaniels
    . Huskies
    . Retrievers
    . Cocker Spaniels
    . Labrado Retrievers
    . Details of Angry expressions
    etc.
    The database problem I am trying to resolve is: how best to narrow selections of groups of Smart Albums? Using the example above, for instance, I have Smart Albums to show me all the detail images of expressions:
    . Dog is Angry
    . Dog is Attentive
    . Dog is Asleep
    . Dog is Tired
    . Dog is Questioning
    . Dog is Relaxed
    How best to narrow those to, for instance, just Huskies? or just Working Dogs? or just the individual dog known as "Nanook's Shadow"?
    Clearly, if each of those is a keyword (or a keyword container), I can simply add the keyword to the Filter. But I want much greater functionality than that.
    By "best" I mean to include the ability to change the variable -- to chose not just "Huskies", but also "Retrievers", and not just "Working Dogs" but also "Hounds". And I want to change this at once -- not individually for each Smart Album.
    What I've come with is clever and borders on elegant (imho - ), but remains a kludge.
    Smart Albums can be subordinate to only Projects and Folders. Subordinating them to Projects does me some, but little, good. (Subordinating them to other Smart Albums, or to regular Albums, would do me more good, but is not allowed.) I therefore created a new parent Folder for each set of Smart Albums I wanted to be able to readily filter as a group, and copied a set of Smart Albums into it. I then set each Smart Album's "Source" to the containing Folder rather than to "Library". At this point, the Smart Albums show no images, which is good. Now, all I have to do is create an Album of images I want the Smart Albums to operate on, and drag that Album into the containing Folder. So I go to my "Hounds" Smart Album, select all images, create new Album with selected images, and drag that into my Folder "Dog Expressions". The Album filters the universe of my Library to just "Hounds" and the Smart Folders filter from that narrowed group.
    This is relatively flexible: If I want to include "Retrievers" as well as "Hounds", I just make another Album and drag it into the "Dog Expressions" Folder. If I want to see only Retrievers, I drag the "Hounds" Album out of the "Dog Expressions" Folder. (So I made a holder Folder called "Sets for Smart Albums" and I keep Albums such as "Retrievers" and "Hounds" there.) I now have a relatively supple drag-and-drop method of filtering groups of Smart Albums all at once.
    But you can already see the problems. First among them is that the Albums are static. I will need to create new Albums in order to include any new images or Versions or whenever I get around to keywording, etc.
    Still with me? Can you help me do better?
    Is there any reason one couldn't have a pivot table based on metadata? One which not only filters but also groups, so that I could have a view showing (for instance) details of Huskies expressions grouped by expression?
    Thanks in advance. If this catches you on Friday, enjoy the weekend.
    Message was edited by: Kirby Krieger

    LOL. Thanks for the laugh -- the slideshows part is especially funny. Are you Aperture certified yet? The test has no surprises at all. It is very well done (exemplary for on-line testing, imho) and covers all parts that it says it will.

  • Terminal: "open -e/t" question.  Windows group question

    2 questions regarding Terminal
    1. Is it possible to make it so the open -e, or open -t command, instead of opening TextEdit, opens a different text editor?
    2. Is it possible to open a Windows group, and have JUST 1 of the windows execute an ssh command?

    1. Is it possible to make it so the open -e, or open -t command, instead of opening TextEdit, opens a different text editor?
    Sure. 'open -t' uses the default text editor application, as defined by LaunchServices. On a standard system this is TextEdit.
    If you want to have 'open -t' use a different TextEditor then you need to specify an alternative application as the default text editor.
    This is easiest done by selecting a plain text (.txt) file in the Finder and choosing File -> Get Info. In the 'Open with' pane you can choose an alternative text editor and clicking the 'Change All' button will update the LaunchServices database with the specified application as the default.
    Now any .txt file you open will launch in this application, whether it's opened in the Finder, or via 'open -t'.

  • Delivery group questions

    Hi,
    Can anybody answer below questions?
    1) Once assigned to a group how can you see the group from the delivery; it’s not in the document flow. I am struggling making this connection.
    2)If multiple deliveries are put into the same delivery group, can they be split into multiple shipments? This seems to be posslble but I am unsure of the
    3)Is there a delivery group monitor to track open (unshipped) delivery groups?
    4) Is there any T-code to group deliveries at IM level. i am sure abt LT45 and VG01 but both of them are at WM level.
    Thanks,
    Bhairav

    Hi Bhairav,
               There is transaction code VL06o, I think this will help you out. Go to this transaction and click "List out bound Deliveries" it will take you in to next screen in that screen you go to Doc.Data there you can find Group field selection there you enter your delivery group and execute the report.
    Regards,
    Murali.

  • WLAN AP Group Question!

    Hi Guys,
    Did anyone know that how many AP Groups can be created by one Controller? (5508)
    May I have 100 AP Groups?
    Thanks

    Q. What is the maximum number of AP Groups that can be configured on a WLC?
    A. This list shows the maximum number of AP groups that you can configure on a WLC:
    A maximum of 50 access point groups for the Cisco 2100 Series Controller and controller network modules
    A maximum of 300 access point groups for the Cisco 4400 Series Controllers, Cisco WiSM, and Cisco 3750G Wireless LAN Controller Switch
    A maximum of 500 access point groups for Cisco 5500 Series Controllers
    http://www.cisco.com/en/US/products/ps6366/products_qanda_item09186a00808b4c61.shtml
    Cheers,
    Steve
    If  this helps you and/or answers your question please mark the question as "answered" and/or rate it, so other users can easily find it.

  • BB curve groups question

    well i just got my 8330 just a few days ago and i love it but i am pulling out my hair on a few things.
    1. ok i am a project manager for a company and have many different companies i deal with, some i need to put about 20 in my phone book. i mad a group with the company name and i put all the contacts in that group. when i go to my phone book i see the group and when i go in everything is ok, all the contacts are in. but when i am outside the group they are listed there to, way to many contacts for me if i just want to find a family or friend. is there any weay to just have the contacts of a group inside a group.
    2. on my BB theme i picked ones with a few icons on the main screen, the one before that shows all icons. is there a way to put the icons that i really use on that screen. i know i can move them but it only moves them on the second screen.              thanksssssss
    Message Edited by billgates on 03-20-2009 05:28 PM

    Welcme to the Frums!
    I am not sure you can do what you ask. i have mine in groups and then they still show up in the regular address book.  It hasnt been a problem as when I go to search for someone I start typing name and their names pops up.  
    Nurse-Berry
    Follow NurseBerry08 on Twitter

  • Grouping question

    HI I am modifying an existing Crystal Reports. I am looking at one, unfortunately without data as yet,
    but looking at the Select expert it has a group header1, 2, and 3. The second and third both have 2 additional sections, 2a and 2b, etc.
    Yet these groups are hidden. How do I figure out what use they are for?

    Hi Philky,
        Look into the report explorer and you can observe what are the groups or sections used in the report and the formuls or fields placed within that section.
    Regards,
    Vinay

  • Dynamic Distribution Groups question

    Can I create a dynamic distribution group based on Exchange Custom Attributes, specifically extensionAttribute6? I haven't used dynamic distribution groups yet, but now we have a need.

    Hello,
    Yes, it is possible. You can create dynamic distribution group using ConditionalCustomAttribute6 parameter: http://technet.microsoft.com/en-us/library/bb125127(v=exchg.150).aspx.

  • AdvancedDatagrid Grouping question

    Getting the hang of this AdvancedDataGrid control. I think it has a lot of potential but I just cant figure out how to do one thing. As you can see from the picture I am grouping by Section and then SubSection. The problem is when there is no subsection data value the items are grouped into a blank folder. Kind of tacky. I wrote this groupLabelingFunction:
    private function groupLabelHandler(data:Object, depth:int):String {
                    var grp:IGroupingCollection = diagnosesGrid.dataProvider.source as GroupingCollection;
                    var grpLabelProperty:String = grp.grouping.label;
                    return (data[grpLabelProperty] == null || data[grpLabelProperty] == "") ? "(No Subsection)" : data[grpLabelProperty];
    And that works great. Instead of a blank folder the folder is titled (No Subsection) however, my boss would instead like those items in that folder to appear in the root of the Section folder. Is there a way to pull them out or get it to ignore the subgrouping when the value is blank?
    Thanks,
    KC

    Hi Guys
    Thanks for your help
    Panda - I think I know what you are meaning but having the lastname in the group header will provide the formatting for the report we require. We really want to show the format as follows
    Client Firstname  Client Lastname    Hour Total
    Jim                     Smith                        8
    Steven                Black                        10
    Would having the lastname in the group header still allow me to keep the above format?
    Travis - I have created the formula you have said however I'm not sure what you mean by "create a group from this formula" can you explain a bit more, sorry I am quite new to crystal reports.
    Thanks

Maybe you are looking for

  • How can I get my mail to open and close it stopped working

    Help! I was able to open and view email last night. I played a new game for several hours and when I went to shut down my computer and it wouldn't allow-it said the mail program was preventing. I tried to open the mail and now it won't open. So I can

  • Content not loading in Dev app.

    Hello, I'm producing our companies first DPS publication, this is the first time I've built an app in DPS, so apologies if I'm missing something obvious. Here's the problem, everything is working fine in Adobe Content Viewer (both the emulator and ap

  • Where is search in the forums

    I have looked on forum pages on how to search a topic. For the life of me I can not find it. The only one I see is at the very top, which takes me out of forums.

  • Calibrating my monitor with other monitors

    I have calibrated my monitor so that output to my personal printer is spot-on. But when I give a CD of digital images that look good on my monitor to someone else, they look washed-out on his/her monitor. Is there a way to standardize monitors, LCD o

  • Terminating PartitionedCache due to unhandled exception:ClassCastException

    I saw this today... A bug? -Andrew Started DefaultCacheServer... 2010-12-22 09:04:49.106/15.625 Oracle Coherence GE 3.6.1.0 <D4> (thread=DistributedCache:DistributedCacheService, member=37): Asking member 1 for 43 primary partitions 2010-12-22 09:04: