sum and group
Hi everyone, consider the following data
{code}
WITH data such AS)
SELECT 111 usd, 777 native, native2 345, 'SB' GROUP_id 'AND' TYPE OF double UNION ALL
SELECT usd 222, 222 native, native2 778, 'SB' GROUP_id, 'AND' TYPE OF double UNION all
SELECT 333 usd, native of 888, 976 native2, GROUP_id 'SB', and ' 1' TYPE OF double UNION all
SELECT 555 usd, native of 976, 236 native2, GROUP_id "SB2", "4" dual UNION all TYPE
SELECT 555 usd, native of 987, 1234 native2, GROUP_id "SB2", "AND" TYPE OF double UNION ALL
SELECT 666 usd, native of 345, 765 native2, GROUP_id "SB2", "ET6" double TYPE
)
{code}
I want to write something like this
Select group_id,
-case when type = 'AND' then
Sum (USD),
Sum (Native)
on the other
Sum (Native)
Sum (native2)
end
from the data
Group_id group
I get the error message because I can't have two columns in a case statement. I know that I can write two different queries and the union of all, but I can run in performance problem because the table is huge.
is there a way to do something similar to the above query in oracle 10g in a single request (no Union all etc.)
Hello
elmasduro wrote:
Hi everyone, consider the following data
{code}
WITH data such AS)
SELECT 111 usd, 777 native, native2 345, 'SB' GROUP_id 'AND' TYPE OF double UNION ALL
SELECT usd 222, 222 native, native2 778, 'SB' GROUP_id, 'AND' TYPE OF double UNION all
SELECT 333 usd, native of 888, 976 native2, GROUP_id 'SB', and ' 1' TYPE OF double UNION all
SELECT 555 usd, native of 976, 236 native2, GROUP_id "SB2", "4" dual UNION all TYPE
SELECT 555 usd, native of 987, 1234 native2, GROUP_id "SB2", "AND" TYPE OF double UNION ALL
SELECT 666 usd, native of 345, 765 native2, GROUP_id "SB2", "ET6" double TYPE
)
{code}
I want to write something like this
Select group_id,
-case when type = 'AND' then
Sum (USD),
Sum (Native)
on the other
Sum (Native)
Sum (native2)
end
from the data
Group_id group
I get the error message because I can't have two columns in a case statement. I know that I can write two different queries and the union of all, but I can run in performance problem because the table is huge.
is there a way to do something similar to the above query in oracle 10g in a single request (no Union all etc.)
What are the results you want from these data? How would you believe that these are good results of these data?
If type is not in the GROUP BY clause, you can not use it in the SELECT clause, unless it is within an aggregate function.
Maybe you want something like this:
SELECT group_id
SUM (CASE WHEN = "AND" THEN usd native ELSE END) AS sum_1
, SUM (CASE type WHEN = 'AND' THEN ELSE END native2 native) AS sum_2
FROM the data
GROUP BY group_id
;
Tags: Database
Similar Questions
-
Problem of sum and group with MSSQL
I'm a quiet complex query after users entry form. The result looks something like this (data simplified, useless and truncated fields)
cat_id | producttext
-------------------------------------
1002 | Parma ham
1013. Bordeaux
5006 | Parma ham
1005. Something
1002 | Another product of Kat 1002
As you can see the first and last record have the same cat_id.
What I want ultimately is to know the percentages of products in the same range (1001-2000, 2001-3000...)
and the percentage of products in the same chat (such as 1002)
I do this simply by a subquery on every Beach, see attached code (query1).
The problem is I don't need only the cat_id but is dependent on the language name.
I can get it with the query as (see query2) but, it used to function if the FROM is another query. It only works if I choose a real table.
All advice what to do different?
What I really want ultimately is a table like this:
2 1002 Fleisch
1 1005 Beilagen, pasta, Reis, Konserven
1 1013 great
This have I done.
I do the join in the 'base' didi - query.Thank you
-
Hello
I have a number of lines where each shows a quantity (in a single column) with a length of wood (in another column), say...
3 4500
2 3000
1 6000
9 3000
1 4500
is there a formula where I can create two additional columns with the sum total of all the required lengths? so, something like this...
11 3000
4 4500
1 6000
the order of length?
also, it will not be fixed lengths, so ideally my formula will order and group some lengths come in the columns.
hope that makes since, cheers, ric
I think I could to make it simpler, in my second list "lengths", list all possible, according to the digital agenda, such as 3000, 3200, 3600, etc. 3800.
in this case, I'm sure that there is a simple way to add the amount of items (in the first column of the first series) each time the length is displayed in the second column (in the first game)...? !
I don't know the best function to use... :-/
-
Sorting and grouping - two months in this query
Hi all
Thanks a lot for JAC
I am doing a project for the construction company, I faced this problem by grouping points according to the relationship between these points the
Relationship is from 1 to 100. If the point between what means there is relationship between these points has come.
resolve this question already, but the results does not correct when the table contains more data.
Jac and thanks a lot to him.
This example for more details
for example, I have these points
In addition, we can see the relationship between these points as followsid location percentage comments 1 loc 1,2 20% that mean point 1 and 2 close to each other by 20% 2 loc 1,3 40% that mean point 1 and 3 close to each other byy 40% 3 Loc 8,6 25% that mean point 8 and 6 close to each other by 25% 4 Loc 6,10 20% 5 LOC 11,10 10 % 6 LOC 15,14 0%
-points 1,2,3 in a group why because close 1.2 and 1.3 a relationship which means 1.3 also hid the relationship.
-Points 6,8,10,11 in the second group there are the relationships between them.
- but no relationship between 1, 2 or 3 with any point of 6,8,9,10,11
-as well as no relationship between 15, 14, which means 14 in the third group and 15 in the fourth group.
Whati need?
to group the points that growing a relationship according to the percentage value
The most important part is to group the points. For EXAMPLE, the query below, the gropuing is not correct.
I have the following table with data
When I used this query, the results is not correctdrop table temp_value; create table temp_value(id number(10),location varchar2(20), percentage number(9)); insert into temp_value values (1,'LOC 1,2',10); insert into temp_value values (2,'LOC 1,3',0); insert into temp_value values (3,'LOC 1,4',0); insert into temp_value values (4,'LOC 1,5',0); insert into temp_value values (5,'LOC 1,6',0); insert into temp_value values (6,'LOC 2,3',0); insert into temp_value values(7,'LOC 2,4',0); insert into temp_value values (8,'LOC 2,5',30); insert into temp_value values (9,'LOC 2,6',0); insert into temp_value values (10,'LOC 3,4',0); insert into temp_value values (11,'LOC 3,5',0); insert into temp_value values (12,'LOC 4,5',40); insert into temp_value values (13,'LOC 4,6',0); insert into temp_value values (14,'LOC 6,7',40); insert into temp_value values (15,'LOC 7,2',0); insert into temp_value values (16,'LOC 8,2',60); insert into temp_value values (17,'LOC 8,3',0); insert into temp_value values (18,'LOC 3,1',0); insert into temp_value values (19,'LOC 9,6',30); insert into temp_value values (20,'LOC 11,2',0); insert into temp_value values (22,'LOC 12,3',10); insert into temp_value values (23,'LOC 19,3',0); insert into temp_value values (24,'LOC 17,3',0); insert into temp_value values (24,'LOC 20,3',0);
resultswith t as (select percentage,loc1,loc2,sum(case when percentage = 0 then 1 when loc1 in (l1,l2) then 0 when loc2 in (l1,l2) then 0 when l1 is null and l2 is null then 0 else 1 end) over(order by rn) sm from ( select id,location,percentage, regexp_substr(location,'\d+',1,1) LOC1, regexp_substr(location,'\d+',1,2) LOC2, lag(regexp_substr(location,'\d+',1,1)) over(order by percentage desc) l1, lag(regexp_substr(location,'\d+',1,2)) over(order by percentage desc) l2, row_number() over(order by percentage desc) rn from temp_value order by percentage desc ) ) select loc,min(sm)+1 grp from( select loc,rownum rn,sm from( select percentage,decode(rn,1,loc1,loc2) loc,sm from t a, (select 1 rn from dual union all select 2 from dual ) b order by percentage desc,decode(rn,1,loc1,loc2) asc ) ) group by loc order by min(sm),min(rn);
SQL > /.
SQL >LOC GRP -------------------- ---------- 2 1 8 1 6 2 7 2 4 3 5 3 9 4 1 5 12 6 3 6 11 13 LOC GRP -------------------- ---------- 19 14 17 15 20 22 14 rows selected.
but the just is
Thanks in advance.Location group No 2 1 8 1 4 1 5 1 1 1 6 2 7 2 9 2 12 3 3 3 19 4 17 5 20 6
Published by: Isabelle on November 30, 2012 03:07OK, I thought an it once again and found out how to include with any such percentage points.
In your example expected output you missed the 11 that's why we got 7 groups now.
The order of the Group 2 and 3 is ambiguous, because the highest percentage of these groups is the same.with connects as ( select distinct loc1 ,loc2 ,connect_by_root(loc1) grp ,percentage per from temp_value --start with --percentage != 0 connect by nocycle (prior loc2 = loc1 or prior loc1 = loc2 or prior loc1 = loc1 or prior loc2 = loc2) and percentage != 0 and prior percentage != 0 ) select loc ,dense_rank() over (order by decode(per,0,1,0), grp) grp from ( select loc ,max(grp) keep (dense_rank first order by per desc, grp) grp ,max(per) keep (dense_rank last order by per nulls first) per from ( select loc1 loc ,grp ,per from connects union select loc2 ,grp ,per from connects ) group by loc ) order by 2,per desc,1 LOC GRP 2 1 8 1 4 1 5 1 1 1 12 2 3 2 6 3 7 3 9 3 11 4 17 5 19 6 20 7
Think we are done now ;-)
Edited by: chris227 at 30.11.2012 16:46Edited by: chris227 at 30.11.2012 17:12
order correctedEdited by: chris227 at 30.11.2012 17:15
simplification, no need to rank in linking subqueryEdited by: chris227 at 30.11.2012 17:26
-
Gap between the sum and more general
We will look after the operation:
CREATE TABLE zzz_null_test AS SELECT 1 double value;
INSERT INTO zzz_null_test 2 SELECT double value;
INSERT INTO zzz_null_test double Value SELECT NULL;
COMMIT;
Can someone tell me why we get the result different by the following statement:
SELECT MySQL zzz_null_test; -Out 3
SELECT 1 + 2 + value NULL FROM dual; -The result will be 0
Thank you
SureshThe aggregate SUM, with many others, function ignores NULL values and calculates their results based on the KNOWN VALUES.
However,.
SELECT 1+2+NULL FROM DUAL
Produces a null result (zero not named) because when you add something to a stranger (NULL) you get an unknown value (NULL).
Quote from the documentation
All except COUNT (*), and GROUPING aggregate functions ignore NULL values. You can use the NVL function in the argument of an aggregation function to substitute a value for a null value. COUNT never returns null, but returns a number or zero. For all remaining aggregate functions, if the data set has no rows, or contains only the rows with NULL values as arguments to the aggregate function, then the function returns null.
-
How can I restore my tabs and groups of tabs after a update to version 36.0?
I work with many tabs when I use Firefox. I keep classified in groups of tabs, which helps to separate the different children to work I do and interests I have. I have been using this environment for years. When I started my job today, Firefox updated to v36.0, and noted the following behaviors:
1. There is only one group of tabs when you try to display tabs at Panorama, as opposed to a dozen groups;
2. normally if the hidden tabs (tabs in the same group as the startup group, and not the default page) downloading of content to what the user clicks on, icon, if any, and the name of the page will show on the tab currently, the tabs display 'New tab' and no icon. It seems, however, the number of tabs that exist across all groups of tabs, but are now ghosts this default value, a group of tabs. I must add, however, I do not count the number of tabs, so I can't be exactly. When you click on it, there is just a blank page. It is so strange that Firefox knows they are there but cannot simply attach the address.
I tried to restore the following files from my backup of Windows Home Server to the folder AppData\Roaming\Mozilla\Firefox\Profiles\ .default < gobbletygook >:
1. in the sessionstore-backups folder, I replaced the files previous.js, recovery.bak and recovery.js (not all of the upgrade ~) with the files yesterday and the day before yesterday.
When that did nothing, I replaced
2 sessionCheckpoints.json
I do not see any file with a recent date that seems to be the one that I have to restore. I should add that I don't see hidden files. I thought about the restoration of the whole of the batch, but didn't know how it would affect the program v36.0 and the profile on 35.0.1 files.
I have deadlines this week and must immediately restore my environment in order to make these possible. I have no address list on my Web pages to work in IE or other. Any help would be much appreciated.
On a second note, I had been wondering recently if this tab group environment is an appropriate way to maintain my work environment. Sometimes, during the opening of Panorama, I would get an error saying a script takes too much time, but if I clicked on continue, it would display the groups in a few seconds. I considered bringing it in bookmarks, but it would be tedious and more difficult to access and open several tabs. Initially, I tried tabs groups thinking it was just a matter of maintaining a table of addresses (in tabs) with a name or an ID of tab group. How that might go wrong? Well, there, so it is obviously more complicated than that, and I did not know that upgrades would affect the data of a personal nature. That I should abandon the use of tab groups?
With the help of information from the user, ptressel, in a post here on the existence of sessionstore.js when version 33 was released, I could easily get my tabs and groups of tabs as follows:
- close Firefox and, perhaps, wait a few seconds (30 years?) for any final closing of files;
- Check if you have a sessionstore.js file in your profile folder, named as I documented in my original post above.
- If this is not timestamped before the discovery of your problem, open the sessionstore-backups folder.
- Check if the recovery.js file is properly stamped and, if not, the recovery.bak.
- At this point, you are likely to find that none of them is before your problem occurring. If so, open your backups from this folder and go through steps 2 to 4 to find a file before your problem occurring.
- When you find a file, copy it to the root of your current profile folder and name it, "sessionstore.js.
- Open Firefox. Mine opened upwards as you wish.
It is a solution for Windows. Sorry I can't comment on other platforms, but I'd bet it's just a copy of file and change of name, it is likely even.
For Windows users, you can find you must sign out and sign in as administrator in order to access backups. You must not logoff your standard account, but do have Firefox closed as described above.
Hope that helps.
-
Is it possible to save the current tabs and groups so that they can be recharged at any time?
My Firefox crashes sometimes, and when I start it up again, my groups and tabs that I had are lost, so I need to recreate my history window. Is there a way I can save the groups that I have with the tabs on the inside so that I can retrieve them at a later date.
"I say that Firefox does not save the whenever I close the browser, so I'm güssing there a file somewhere that contains this information, if I know how is called this file I could save it on my regular schedule and retrieve them if I had to, of course the best solution would be to have a ' save the groups ' & 'Support groups' in the menu.Thanks in advance
DayoJ(PIN) App tabs and groups of tabs (Panorama) are stored in session data in the sessionstore.js file in the Firefox profile folder.
You can use this button to go to the Firefox profile folder currently in use:
- Help > troubleshooting information > profile directory: see file (Linux: open the directory;) Mac: View in the Finder)
- http://KB.mozillazine.org/Profile_folder_-_Firefox
-
Research Protect deleted all my tabs and groups of Firefox
I had about 200 tabs grouped together in about 30 groups of 31.0 Firefox (latest version). The Group appeared when I clicked on the icon to the left of the button "minimize" or press CTRL + SHIFT + E. It is called "your Firefox tabs - group". I also use Xmarks, but I have disabled Synchronization tab recently.
Generally all the tabs and their groups have been saved when I closed Firefox. Today I opened Firefox and all tabs and groups disappeared! Instead, it opens some search engine called Trovi (www.trovi.com) with "bing results. Its the same in Chrome, Opera and IE.
My OS is Windows 8.1 update 1 with all updates installed. My antivirus is Avast! with all updates installed. There was some malware installed of course, but I'm not awake me. I ran a 'full system test' in Avast! latest updates, which is the deeper analysis that I know (without my laptop HP ProBook 4730 s restaring). No viruses were found.
I'm suspecting a program called 'Research Protect' version 2.16.10.61 'Client Connect Ltd. It was installed with PowerISO 6.0 x 64.
I tried to run the system restore, but it seems that all the restore points I ever created are now deleted! I discovered this by opening the system properties-> system-> system restore Protection. However, 'Protection' is 'On' for my system disk.
How can I restore my tabs and groups? It is extremely important for me.
Accidentally, I posted my question twice - my apologies. I marked this as resolved and will continue to ask for help on the other.
https://support.Mozilla.org/Ta/questions/1014087
Thank you!
-
How can I remove comments from the users and groups
I have my in my users and groups in the system preferences a user snd invited another user
How can I remove them
Go to Preferences system-> users and groups, and then press the lock to allow you to change the settings. Then choose 'user comments' in the sidebar and uncheck "Allow clients to connect to this computer". This will not make this option disappear, but after that you will not be able to use the Guest user.
«Respect for the other user, simply choose it in the sidebar and press on the '-' button.» Make sure that no one uses this user.
-
tabs and groups of tabs are lost
Closing Firefox and then restarting him, invariably all my tab groups seem to have lost their legs. Reopening of groups of Eve extended or closed (using the Group Manager add-on tab) will not help.
It is not happened on my previous install but have since upgraded to Kubuntu 14.04 and Firefox 29 (to be precise Firefox to canonical 1.0), I keep losing my tabs and groups of tabs.
Don't know what mistake I make.
In case you use "clear history of Firefox closing:
- do not erase browsing history
- Edit > Preferences > privacy > Firefox will be: "Use the custom settings for history": [X] 'Clear history of Firefox closing' > settings
- https://support.Mozilla.org/KB/remove-browsing-search-and-download-history
Note that compensation "Preferences of Site" clears all exceptions for cookies, images, pop-up windows, installation of software, passwords, and other specific data from Web site.
You can check for problems with the sessionstore.js and sessionstore.bak files in the profile folder of Firefox that store session data.
Rename (or delete) the sessionstore.js file and possible sessionstore-# .js files with a number and sessionstore.bak in the Firefox profile folder.
- Help > troubleshooting information > profile directory: see file (Linux: open the directory;) Mac: View in the Finder)
- http://KB.mozillazine.org/Profile_folder_-_Firefox
- http://KB.mozillazine.org/Multiple_profile_files_created
Delete sessionstore.js will cause App Tabs and groups of tabs open and closed tabs (back) to get lost and you will have to re-create them (take note or bookmarks if possible).
-
How can I remove the administrator in users and groups
I give my MacBook to a family member. I just upgraded to El Capitan.
I opened system preferences > users and groups > and added my brother as a new user and administrator. I was unable to remove me as an administrator, and now I can't stop computer without getting the warning "stop can cause other users connected to this computer to lose unsaved changes." If I switch to the user the same message appears then try to stop.
Help please
What to do before you sell or give away your Mac - Apple Support
-
I just install my new Iomega PX4 - 300 d and have enabled security. When I go to the users section and groups, there is no Add button to create new users or groups.
The Add button is available in other sections and I created with success of new volumes/shares.
I read the instructions and following the guides online without success.
Is there another setting that I missed?
He solved.
I disabled the security and then reactivated it.
The add users/groups button reappears.
-
I took to allow a user to administer by checking the box "Allow user to administer this computer" of the user in the users window and groups in system preferences.
I tried to uncheck the box, but it remains unchanged.
You must be logged in as a different user than the one you are trying to change, and your own user name must be an administrator on this system.
-
What are the differences between the services and site domain group policy and group policy?
What are the differences between the services and site domain group policy and group policy?
Server must wonder about the Technet site. http://social.technet.Microsoft.com/forums/en-us/home
-
Suddenly can't access local users and groups permissions list
In computer management (my computer / manage) "Local users and groups" icon has a red x on it and when I click on it I get this message:
Local users and groups
Unable to access the computer {computer name} toa. The error was: library not registered.How can I find which library is not registered, so I can register?
BTW, this is one of several very similar problems that began to arrive after the last update of Microsoft Windows Vista.
Hello GCCarvill,
Thanks for posting your question in the Microsoft answers Forum.
If you have a system restore point, before applying the updates would be the fastest way to restore the library file
who is missing. Use the following article to restore to an earlier point in time. Don't forget to create a manual restore point before using an earlier version of the operating system.936212 KB - how to repair the operating system and how to restore the configuration of the operating system to an earlier point in time in Windows Vista
http://support.Microsoft.com/kb/936212You can also create a manual system restore point so that you can restore in case of problems.
How to create a system restore point manually:
Right-click on the computer icon in the desktop, then choose Properties
In the left pane, click System Protection
Alternatively, to directly access the System Protection tab, click Start and type SystemPropertiesProtection.exe.
If you are prompted for an administrator password or a confirmation, type the password or provide confirmation.
Click the System Protection tab and then click on create.
In the System Protection dialog box, type a description, and then click on create.After the search for the other forums, I found another user having a similar problem. They used a tool called FileMon and after comparison, they discovered a file called activeds.tlb was missing. They have restored a copy in the system32 directory and
was then able to access the local users and groups successfully. You can download a copy of FileMon of:
http://www.sysinternals.comIf please reply back and let us know if it helped to solve your problem or if you need further assistance.
Thank you
Marilyn
Microsoft Answers Support Engineer
Visit our Microsoft answers feedback Forum and let us know what you think.
Maybe you are looking for
-
Where did the "orientation Lock" parameter passed on my iPad?
My "Lock Orientation" button disappeared in my quick settings and is now a button "Mute". Where can I configure the direction to lock now? Thank you PMC Version of the IOS is 9.2.1 (13D 15)
-
Fixed size array has no cases of change of value
I am running LabVIEW 9.0 on Windows XP, develop for Windows and cRIO (RT and FPGA). I created an array of fixed size (4 items) of fixed point numbers. I have put at the disposal of the control to the user on the Panel before Windows. I plan to pass t
-
screen does not rotate on stream 7
Hi, screen has stopped rotating 2 hours after purchase. ? installed office and that's the only thing that I did before that happens... any ideas. I ve left swiped and the screen is unlocked. Thank you
-
Output HDMI not working do not after Windows 8.1 update
I use an envy TouchSmart 15 and I just launched an update of Windows based on the automatic system update 8.1 (he ran 5 updates). Before the update, I've used a 27 "monitor in the main screen, and it was connected via the HDMI port. Just after the u
-
* Original title: attachments Help, please. I did something wrong (AGAIN!) I had no problem with access to attachments to my e-mails, but a problem occurred just. I can longer open attached pdf files. I am able to preview the files, but they are too