sql - Querying data groups with total row before starting next group? -


Let me ask some data in the format given below in SQL Server:

  • ID groups Value
  • 1A10
  • 2A20
  • twenty 30

  • 1b6

  • 2b 4
  • 10 points

  • 2 c 200
  • even 300

    I had to do it in simulation steps

  • The query in one group
  • The amount in the other query
  • The union operator to combine this result set Abuse or
  • Back to all sub-set of data using the steps 1-3 for all groups and finally union.

    Is there a better way to do this? Can some use of the box feature? Please advise.

    Edit:

    According to the suggestions and code samples I tried this code:

      Select Case ID Zero then 'Yoga' as the rest of the cast id, in the end, the case (id as VARCHAR (10)), when [group] null then 'all' remaining cast ([group] as VARCHAR (50)) [ Group] as the value from the price (Selection Number, [Group], bGAApplicationID, Section, SUM (PrimaryTotalArea) vwFacilityDetails as the price from where the Eid, [Group], bGAApplicationID, rollup by section by bgaapplic Ationid = 1102 group)   

    And even with this code:

      select Eid, [Group], BGAApplicationID , Section, SUM (PrimaryTotalArea) did not form the price from vwFacilityDetails ([Group] is null and the ID is empty and BGAApplicationId is empty and section is empty) and BGAApplicationId = 1102 Eid based on group, [Group], BGAApplicationID , With rollup stream   

    The results of this data group but for every record it shows that this is 3 times (in both the above code) 2879 Existing Facilities: Full School 25.00

  • 2879 Existing Facilities Full School 25.00
  • 2879 Existing Facilities Full School 25.00
  • 2879 All 25.00

    I think there is a problem in my query, please guide me here too. Thank you

    The SQL server that you should have used to use is that. MS SQL Server 2008 Schema Setup :

      table vwFacilityDetails (do not create id int, [group] Four (1) not empty, primitatariacera int null, section int, bugapplecid int); VwFacilityDetails (ID, [group], section, bgaapplicationid, PrimaryTotalArea) value (1, 'A', 1,1102,2), (1, 'A', 1,1102,1), (1, 'A ', 1,1102,7), (2,' A ', 1,1102,20), (1,' b ', 1,1102,6), (2,' b ', 1,1102,4) , (1, 'c', 1,1102,100), (2, 'c', 1,1102,200); Select   

    Query 1 :

      is the case when Eid Null is then the 'yoga' remaining rights (id, 10) [Group], bGAApplicationID, section, SUM (PrimaryTotalArea) vwFacilityDetails from [GROUP] order, id grouping by set ((number, [group], bGAApplicationID, section), ([group])) bgaapplicationid = 1102 group;   

    :

      | ID | Group | BGAAPPLICATIONID | Section | PRICE | -------------------------------------------------- - | 1 | A. 1102 | 1 | 10 | | 2 | A. 1102 | 1 | 20 | | SUM | A. (Faucet) | (Faucet) | 30 | | 1 | B 1102 | 1 | 6 | | 2 | B 1102 | 1 | 4 | | SUM | B (Faucet) | (Faucet) | 10 | | 1 | C. 1102 | 1 | 100 | | 2 | C. 1102 | 1 | 200 | | SUM | C. (Faucet) | (Faucet) | 300    

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -