Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL Query Problem

SQL Query Problem

Scheduled Pinned Locked Moved Database
databasehelp
13 Posts 6 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Syed Shahid Hussain
    wrote on last edited by
    #1

    hi I want to make a query for this data can any one of u help me; DATA:

    Person       Name         value
    XYZ          a            10
    XYZ          b            5 
    XYZ          a            15
    XYZ          b            4
    XYZ          c            1
    XYZ          a            5
    XYZ          d            10
    XYZ          a            10
    ...
    ...
    

    This is the of one group; now for I want this result for this data and so on;

    Person      Name         Total
    XYZ         a            40
    XYZ         others       20
    abc         a            ##
    abc         others       ##
    

    Please write a query for this. Thanks :rose:

    Syed Shahid Hussain

    D J N 3 Replies Last reply
    0
    • S Syed Shahid Hussain

      hi I want to make a query for this data can any one of u help me; DATA:

      Person       Name         value
      XYZ          a            10
      XYZ          b            5 
      XYZ          a            15
      XYZ          b            4
      XYZ          c            1
      XYZ          a            5
      XYZ          d            10
      XYZ          a            10
      ...
      ...
      

      This is the of one group; now for I want this result for this data and so on;

      Person      Name         Total
      XYZ         a            40
      XYZ         others       20
      abc         a            ##
      abc         others       ##
      

      Please write a query for this. Thanks :rose:

      Syed Shahid Hussain

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      Syed Shahid Hussain wrote:

      Please write a query for this.

      Why?

      It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

      S 1 Reply Last reply
      0
      • D dan sh

        Syed Shahid Hussain wrote:

        Please write a query for this.

        Why?

        It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

        S Offline
        S Offline
        Syed Shahid Hussain
        wrote on last edited by
        #3

        very stupid, if u dont know then say "i dont know sorry" what do u mean by WHY?

        Syed Shahid Hussain

        D 1 Reply Last reply
        0
        • S Syed Shahid Hussain

          very stupid, if u dont know then say "i dont know sorry" what do u mean by WHY?

          Syed Shahid Hussain

          D Offline
          D Offline
          dan sh
          wrote on last edited by
          #4

          Syed Shahid Hussain wrote:

          if u dont know then say "i dont know sorry"

          Instead, I do not reply if I do not know anything about the question.

          Syed Shahid Hussain wrote:

          what do u mean by WHY?

          Is this a quiz website? No. Why should I do your work? If you had tried something and got stuck, then many would be interested to help you.

          It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

          S 1 Reply Last reply
          0
          • D dan sh

            Syed Shahid Hussain wrote:

            if u dont know then say "i dont know sorry"

            Instead, I do not reply if I do not know anything about the question.

            Syed Shahid Hussain wrote:

            what do u mean by WHY?

            Is this a quiz website? No. Why should I do your work? If you had tried something and got stuck, then many would be interested to help you.

            It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

            S Offline
            S Offline
            Syed Shahid Hussain
            wrote on last edited by
            #5

            d@nish wrote:

            Is this a quiz website?

            brother it is a forum I think u dont know the meaning of forum, here people help each other without Why? and without any thing. I'd solved my problem but I want some suggestions from others. Now if u know any idea about that then reply otherwise keep quiet thank you very much.

            Syed Shahid Hussain

            D 1 Reply Last reply
            0
            • S Syed Shahid Hussain

              d@nish wrote:

              Is this a quiz website?

              brother it is a forum I think u dont know the meaning of forum, here people help each other without Why? and without any thing. I'd solved my problem but I want some suggestions from others. Now if u know any idea about that then reply otherwise keep quiet thank you very much.

              Syed Shahid Hussain

              D Offline
              D Offline
              dan sh
              wrote on last edited by
              #6

              People here help those who help themselves. People here do not prefer spoon feeding in general. Try out something or search google. If you face any problems, then post the query.

              It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

              S 1 Reply Last reply
              0
              • D dan sh

                People here help those who help themselves. People here do not prefer spoon feeding in general. Try out something or search google. If you face any problems, then post the query.

                It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

                S Offline
                S Offline
                Syed Shahid Hussain
                wrote on last edited by
                #7

                I've said that I've solved the problem but I want some perfect solution from the experts, why are u arguing me, and who has given u this right to argue with me.

                Syed Shahid Hussain

                L 1 Reply Last reply
                0
                • S Syed Shahid Hussain

                  hi I want to make a query for this data can any one of u help me; DATA:

                  Person       Name         value
                  XYZ          a            10
                  XYZ          b            5 
                  XYZ          a            15
                  XYZ          b            4
                  XYZ          c            1
                  XYZ          a            5
                  XYZ          d            10
                  XYZ          a            10
                  ...
                  ...
                  

                  This is the of one group; now for I want this result for this data and so on;

                  Person      Name         Total
                  XYZ         a            40
                  XYZ         others       20
                  abc         a            ##
                  abc         others       ##
                  

                  Please write a query for this. Thanks :rose:

                  Syed Shahid Hussain

                  J Offline
                  J Offline
                  J4amieC
                  wrote on last edited by
                  #8

                  Syed Shahid Hussain wrote:

                  Please write a query for this.

                  Only because you used "Please" am I replying to this. This may be a forum where people help each other, but it is NOT a place where professionals will do your work for you. Most professionals charge for professional work. Instead, we help people who are stuck on a problem. A pre-requisite to getting help is showing that you are able to at least have a stab at doing it yourself, and therefore when you hit a specific problem, people here are more than happy to help. But just saying "Please do x for me" will get you either the reply you've gotton above, or a quotation. I can do this work for you at £50 + VAT per hour and I imagine with implementation and testing there is 3 hours work there.

                  M 1 Reply Last reply
                  0
                  • S Syed Shahid Hussain

                    I've said that I've solved the problem but I want some perfect solution from the experts, why are u arguing me, and who has given u this right to argue with me.

                    Syed Shahid Hussain

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #9

                    Syed Shahid Hussain wrote:

                    I've solved the problem

                    Then I suggest you show your solution and ask if anyone sees ways to improve on it. That way typically leads to a more interesting thread. :)

                    Luc Pattyn


                    I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                    Local announcement (Antwerp region): Lange Wapper? Neen!


                    S 1 Reply Last reply
                    0
                    • L Luc Pattyn

                      Syed Shahid Hussain wrote:

                      I've solved the problem

                      Then I suggest you show your solution and ask if anyone sees ways to improve on it. That way typically leads to a more interesting thread. :)

                      Luc Pattyn


                      I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                      Local announcement (Antwerp region): Lange Wapper? Neen!


                      S Offline
                      S Offline
                      Syed Shahid Hussain
                      wrote on last edited by
                      #10

                      leave it dear, now first time i'm irritating with this site, code project. Every time when i post a question i received a perfect solution or at least pleasant comments not like these stupid phrases. One want 3 hr to solve it and i'd given only 2 hr to solve it and make related crystal report with complete formatting. now just stop posting replies on this question.

                      Syed Shahid Hussain

                      1 Reply Last reply
                      0
                      • J J4amieC

                        Syed Shahid Hussain wrote:

                        Please write a query for this.

                        Only because you used "Please" am I replying to this. This may be a forum where people help each other, but it is NOT a place where professionals will do your work for you. Most professionals charge for professional work. Instead, we help people who are stuck on a problem. A pre-requisite to getting help is showing that you are able to at least have a stab at doing it yourself, and therefore when you hit a specific problem, people here are more than happy to help. But just saying "Please do x for me" will get you either the reply you've gotton above, or a quotation. I can do this work for you at £50 + VAT per hour and I imagine with implementation and testing there is 3 hours work there.

                        M Offline
                        M Offline
                        mnatarajakumaran
                        wrote on last edited by
                        #11

                        try this, select person , name, sum(tot_values) from ( select person, case when name = 'a' then 'a' else 'others' end as name , sum(tot_values) as tot_values from test_tabb group by person,name ) X group by person,name order by person desc, name

                        J 1 Reply Last reply
                        0
                        • M mnatarajakumaran

                          try this, select person , name, sum(tot_values) from ( select person, case when name = 'a' then 'a' else 'others' end as name , sum(tot_values) as tot_values from test_tabb group by person,name ) X group by person,name order by person desc, name

                          J Offline
                          J Offline
                          J4amieC
                          wrote on last edited by
                          #12

                          Why would I want to try that? I didnt ask how to do it in the first place! Besides, theres a far simpler way with about half as many lines. (Hint: You can user a case statement in a group by clause ;))

                          1 Reply Last reply
                          0
                          • S Syed Shahid Hussain

                            hi I want to make a query for this data can any one of u help me; DATA:

                            Person       Name         value
                            XYZ          a            10
                            XYZ          b            5 
                            XYZ          a            15
                            XYZ          b            4
                            XYZ          c            1
                            XYZ          a            5
                            XYZ          d            10
                            XYZ          a            10
                            ...
                            ...
                            

                            This is the of one group; now for I want this result for this data and so on;

                            Person      Name         Total
                            XYZ         a            40
                            XYZ         others       20
                            abc         a            ##
                            abc         others       ##
                            

                            Please write a query for this. Thanks :rose:

                            Syed Shahid Hussain

                            N Offline
                            N Offline
                            Niladri_Biswas
                            wrote on last edited by
                            #13

                            Try this declare @tbl table(person varchar(50),name varchar(50),value int) insert into @tbl select 'xyz','a',10 union all select 'xyz','b',5 union all select 'xyz','a',15 union all select 'xyz','b',4 union all select 'xyz','c',1 union all select 'xyz','a',5 union all select 'xyz','d',10 union all select 'xyz','a',10 union all select 'abc','a',0 union all select 'abc','b',0 union all select 'abc','c',0 union all select 'abc','d',0

                            ;with cte as
                            (
                            select person,name,sum(value) as total from @tbl group by person,name
                            )

                            select person,'others' as name , SUM(total) as total from cte where name not in('a')
                            group by person
                            union all
                            select person,'a' as name , SUM(total) as total from cte where name in('a')
                            group by person
                            order by person desc

                            :)

                            Niladri Biswas

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups