GROUP BY confusion - group-by

I am pulling through some data in SQL Server and I would like to GROUP BY my results but cannot get it to work.
This is my current SQL statement:
SELECT
PA01201.CUSTNMBR,
PA01201.PACONTNUMBER,
PA01201.PAcontid,
PA01100.CUSTNMBR AS Expr1,
PA01100.PAcontname,
PA01100.PAcontid AS Expr2,
PA01100.PACONTNUMBER AS Expr3,
PA01201.PAprojname,
PA01201.PAPROJNUMBER
PA01201.Cost
FROM
PA01201
INNER JOIN
PA01100 ON PA01201.CUSTNMBR = PA01100.CUSTNMBR AND
PA01201.PACONTNUMBER = PA01100.PACONTNUMBER AND
PA01201.PAcontid = PA01100.PAcontid
It returns these results:
CUSTNMBR PACONTNUMBER PAcontid Expr1 Pacontname Expr2 Expr3 Paprojname PAPROJNUMBER Cost
AD001 8051 8051 AD001 Company 1 8051 8051 Project 1 08051P 951
AP001 8063 8063 AP001 Company 2 8063 8063 Project 2 08063P 2651
AR002 8096 8096 AR002 Company 3 8096 8096 Project 3 08096P 807
AR003 9033 9033 AR003 Company 4 9033 9033 Project 4 09033P 458
AS001 8013 8013 AS001 Company 5 8013 8013 Project 5 08013C 3297
AS001 8013 8013 AS001 Company 5 8013 8013 Project 5 08013P 48
AS001 8013 8013 AS001 Company 5 8013 8013 Project 5 08013P 641
AR002 8096 8096 AR002 Company 3 8096 8096 Project 3 08096P 1000
I would like to be able to group the result by PAcontid.
Can anyone advise the easiest way to do this?
When I try and insert a GROUP BY clause I get an error stating that the other columns (CUSTNMBR, PAPROJNUMBER) etc are not included in the clause????
Any help much appreciated.
All work is being done in SQL Server Management Studio 2008 R2
Sorry for some reason my last column (Cost) didn;t come through. I have updated my question to show the proper fields. Basically what I am trying to do is get a total cost for each Pacontid.
I would like my results to look something like ........
CUSTNMBR PACONTNUMBER PAcontid Expr1 Pacontname Expr2 Expr3 Paprojname PAPROJNUMBER Cost
AS001 8013 8013 AS001 Company 5 8013 8013 Project 5 08013P 3986
AD001 8051 8051 AD001 Company 1 8051 8051 Project 1 08051P 951
AP001 8063 8063 AP001 Company 2 8063 8063 Project 2 08063P 2651
AR002 8096 8096 AR002 Company 3 8096 8096 Project 3 08096P 1807
AR003 9033 9033 AR003 Company 4 9033 9033 Project 4 09033P 458
Is this possible in what I am trying to do?

When using GROUP BY, all the selected columns must be in the GROUP BY clause or, if not, an aggregate function (ex: SUM, MAX, MIN, AVG) around it!
For more info, check THIS.
In you case, a possible solution might be:
SELECT MAX(PA01201.CUSTNMBR),
MAX(PA01201.PACONTNUMBER),
PA01201.PAcontid,
MAX(PA01100.CUSTNMBR AS Expr1,
MAX(PA01100.PAcontname),
MAX(PA01100.PAcontid) AS Expr2,
MAX(PA01100.PACONTNUMBER) AS Expr3,
MAX(PA01201.PAprojname),
MAX(PA01201.PAPROJNUMBER)
FROM PA01201
INNER JOIN PA01100 ON PA01201.CUSTNMBR = PA01100.CUSTNMBR
AND PA01201.PACONTNUMBER = PA01100.PACONTNUMBER
AND PA01201.PAcontid = PA01100.PAcontid
GROUP BY PA01201.PAcontid

Add all the selected columns in the GROUP BY clause. But first start with the desired column: PAcontid.
SELECT
PA01201.CUSTNMBR,
PA01201.PACONTNUMBER,
PA01201.PAcontid,
PA01100.CUSTNMBR AS Expr1,
PA01100.PAcontname,
PA01100.PAcontid AS Expr2,
PA01100.PACONTNUMBER AS Expr3,
PA01201.PAprojname, PA01201.PAPROJNUMBER
FROM
PA01201
INNER JOIN
PA01100 ON PA01201.CUSTNMBR = PA01100.CUSTNMBR AND
PA01201.PACONTNUMBER = PA01100.PACONTNUMBER AND
PA01201.PAcontid = PA01100.PAcontid
GROUP BY
PAcontid, CUSTNMBR, PACONTNUMBER, PAcontname, PAprojname, PAPROJNUMBER

Perhaps you mean to "group" them by that visually but not in the same way SQL does, if you added an
Order by CUSTNMBR , PAcontid
which will give you a list of customers on the left in order then the data in groups of PAcontid ..
or
Order by PAcontid ,CUSTNMBR
which will sort it by PAcontid and then put the customers in order..
Normally you would do say
ann apple 10
pete strawberry 3
Lucy strawberry 12
select fruit, sum(count) as total from lunch group by fruit
to get
apple 10
strawbery 15

Related

How to GetOsVersion on Windows 10 using perl

I've been using Win32::GetOSVersion() perl function to get the destination's OS version. However, this API call does have support only upto Windows Server 2012.
http://search.cpan.org/~jdb/Win32-0.52/Win32.pm
OS ID MAJOR MINOR
---------- --- ----- -----
Win32s 0 - -
Windows 95 1 4 0
Windows 98 1 4 10
Windows Me 1 4 90
Windows NT 3.51 2 3 51
Windows NT 4 2 4 0
Windows 2000 2 5 0
Windows XP 2 5 1
Windows Server 2003 2 5 2
Windows Server 2003 R2 2 5 2
Windows Home Server 2 5 2
Windows Vista 2 6 0
Windows Server 2008 2 6 0
Windows 7 2 6 1
Windows Server 2008 R2 2 6 1
Windows 8 2 6 2
Windows Server 2012 2 6 2
Is there any other way/approach where I can get the OS version on Windows 10 too?
There are a few other ways to get the raw data, which you could then parse to fit your application, e.g.
#!/usr/bin/perl
use strict;
use warnings;
my $ver = `ver`;
print "output of ver command: $ver\n";
my $reg = `reg query "HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion" /v "ProductName"`;
# alternatively query for 'CurrentVersion' rather than 'ProductName' above
print "output of registry query: $reg\n";
Win32 module uses GetVersionExA (see Win32.xs) and as per msdn:
In Windows 8.1 and Windows 10, the GetVersion and GetVersionEx
functions have been deprecated. In Windows 10, the VerifyVersionInfo
function has also been deprecated. While you can still call the
deprecated functions, if your application does not specifically target
Windows 8.1 or Windows 10, you will get Windows 8 version (6.2.0.0).
Source: msdn
Also see: IsWindows10OrGreater function
If you get to fix it, kindly open a pull request :)

Creating an eclipse plugin without gui: what am I missing?

I'm creating an eclipse plugin using java code generated via a Makefile (yes, I know ant). The final target of my makefile is a zip containing the following structure (I used the plugin for javacc as an inspiration):
$ unzip -l myplugin_2015.02.16.zip
Archive: myplugin_2015.02.16.zip
Length Date Time Name
--------- ---------- ----- ----
0 02-16-2015 09:30 feature/
0 02-16-2015 09:30 feature/myplugin.feature_2015.02.16/
474 02-16-2015 09:30 feature/myplugin.feature_2015.02.16/feature.xml
0 02-16-2015 09:30 plugins/
0 02-16-2015 09:30 plugins/myplugin_2015.02.16/
0 02-16-2015 09:30 plugins/myplugin_2015.02.16/META-INF/
527 02-16-2015 09:30 plugins/myplugin_2015.02.16/META-INF/MANIFEST.MF
492 02-16-2015 09:30 plugins/myplugin_2015.02.16/plugin.xml
23079 02-16-2015 09:30 plugins/myplugin_2015.02.16/idp192.jar
--------- -------
24572 9 files
No I'd like to import this zip in eclipse as a new plugin. When I run eclipse->install-new-software->Add->archive it fails with "no software size found for jar:... , do you wish do edit location ?".
I suspect I need to wrap this zip in a site file ? is there a minimal way to create this 'site' archive ? or is there a simplier solution , something missing in my plugin.zip ? Most important, I don't want to use any GUI.
Thank you for your help
fixed a few hours later: just moving my *.jar to eclipse/plugin fixed the problem.

Maple: command to simplify fraction

Why doesn't Maple simplify a fraction like
-sqrt(5)*(5+sqrt(5))/120
to (-1-sqrt(5))/24 ?
Are there any commands to do this?
A suitable command for this is radnormal.
ee:=-sqrt(5)*(5+sqrt(5))/120;
1 (1/2) / (1/2)\
ee := - --- 5 \5 + 5 /
120
radnormal( ee );
1 1 (1/2)
- -- - -- 5
24 24
There are a few others which can get the form (at least for this particular example).
expand( ee );
1 1 (1/2)
- -- - -- 5
24 24
evala(Normal( ee ));
1 1 (1/2)
- -- - -- 5
24 24
Note that the distribution of the factor 1/24 is done here by Maple as an automatic simplification (and which is usually difficult to disable or awkward to avoid). Notice how delayed evaluation won't prevent it.
'(-1-sqrt(5))/24';
1 1
- -- - -- sqrt(5)
24 24

printing groups in 4 column report in crystal 2008

I want to print a report in crystal 2008. This is 4 column report. My source query is in oracle 11g.
layout of report is something like that:
List of consumers feeder wise/tariff wise
> Feeder/Tariff 10002 10003 10004 10005
> a-1 216 300 230 14
> b-1 23 3 17 19
> c-1 26 4 19 25

Xcode crashing on startup "parentPath must be nil but it is not"

I'm having XCode (latest version) crash whenever I start up - can't get anything done until I resolve this - any ideas?
Error - See below
What I did prior to getting the issue
had put in a new HDD (and moved the old to the optical bay) - reinstalled XCode 4 on the new SSD - all working fine
I did rename my home directory user name on the "old" HDD to put "_OLD" at the end - just so I didn't get confused if jumping to the old HDD for files
I tried to open a test project from this old HDD area - got some issue opening it (can't remember details) - closed/restarted fromhere
Then after this every time I try to open XCode a fresh it's like it tries to open the last projects that was open including this one I had an issue with - get the below error - can't continue on using xcode have to crash out
Error:
ASSERTION FAILURE in /SourceCache/DVTFoundation/DVTFoundation-903/Framework/Classes/FilePaths/DVTFilePath.m:322
Details: fsrep is absolute (starts with tilde) ('~--814203924d469071-0000000000') parentPath must be nil but it is not ('<DVTFilePath:0x401bdf9e0:'/Volumes/Macintosh HD/Users/greg/.dvdcss'>')
Object: <DVTFilePath>
Method: +_filePathForParent:fileSystemRepresentation:length:allowCreation:
Thread: <NSThread: 0x40010a260>{name = (null), num = 1}
Hints: None
Backtrace:
0 0x0000000103f44466 -[IDEAssertionHandler handleFailureInMethod:object:fileName:lineNumber:messageFormat:arguments:] (in IDEKit)
1 0x00000001035b3794 _DVTAssertionFailureHandler (in DVTFoundation)
2 0x0000000103550a9e +[DVTFilePath _filePathForParent:fileSystemRepresentation:length:allowCreation:] (in DVTFoundation)
3 0x0000000103550963 +[DVTFilePath _filePathForParent:pathString:] (in DVTFoundation)
4 0x0000000103b95642 -[DVTFilePath(IDESourceControlStatus) IDESourceControl_importantSubpaths] (in IDEFoundation)
5 0x0000000103b414ac -[IDEFileReference _updateSourceControlStatusIfNeeded] (in IDEFoundation)
6 0x0000000103b37951 -[IDEWorkspace _updateSourceControlStatusIfNeeded] (in IDEFoundation)
7 0x00007fff8c2eb25a __NSFireDelayedPerform (in Foundation)
8 0x00007fff8b82df84 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ (in CoreFoundation)
9 0x00007fff8b82dad6 __CFRunLoopDoTimer (in CoreFoundation)
10 0x00007fff8b80e471 __CFRunLoopRun (in CoreFoundation)
11 0x00007fff8b80dae6 CFRunLoopRunSpecific (in CoreFoundation)
12 0x00007fff8b3633d3 RunCurrentEventLoopInMode (in HIToolbox)
13 0x00007fff8b36a63d ReceiveNextEventCommon (in HIToolbox)
14 0x00007fff8b36a4ca BlockUntilNextEventMatchingListInMode (in HIToolbox)
15 0x00007fff86bde3f1 _DPSNextEvent (in AppKit)
16 0x00007fff86bddcf5 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] (in AppKit)
17 0x00007fff86bda62d -[NSApplication run] (in AppKit)
18 0x00007fff86e5980c NSApplicationMain (in AppKit)
19 0x0000000103549eec (in Xcode)
20 0x0000000000000002
I had the same problem.
It was due to a file fo which the name started by ~ in the directory path given by Xcode when it crashed.
Check if you don't have such a file and delete it.
In my case, it solved the issue.
Hope this help,
Rds,
Michael
The solution that worked for me is to delete the Xcode autosave files in ~/Library/Autosave Information. Xcode then started up clean for me.
may not be best answer (?) however I had to (a) reinstall + (b) delete all the various XCode files scattered through my home directory...then it started up ok
Step 1: Copy all the code you want to keep into text files or
something like that
Step 2: Un-install
Step 3: make some coffee
Step 4: Re-install
Details: fsrep is absolute (starts with tilde) ('~--814203924d469071-0000000000') parentPath must be nil but it is not ('<DVTFilePath:0x401bdf9e0:'/Volumes/Macintosh HD/Users/greg/.dvdcss'>')
Object: <DVTFilePath>
in my case the file referenced was dropbox's cache, so the error looked like this
must be nil but it is not ('<DVTFilePath:0x401bdf9e0:'/Volumes/Macintosh HD/Users/greg/.dropbox.cache.2.25.12'>')
after some research on dropbox forums i found these cache directories can be deleted. after removal xcode worked fine.
so i would tell future people who come here to try and remove the offending file prior to reinstalling xcode. (or rename it if you cant delete it)
I deleted ~/Library/Preferences/com.apple.dt.Xcode.plist and Xcode started normally again.
In my case I was xcodebuild'ing Xcode UI Tests from command line using custom .xcconfig file:
HERE_BUILD=./Build-command-line
HERE_INTERMEDIATES=$(HERE_BUILD)/Intermediates
// Paths
// the following paths are enough to redirect everything to $HERE_BUILD
MODULE_CACHE_DIR = $(HERE_BUILD)/DerivedData/ModuleCache
OBJROOT = $(HERE_INTERMEDIATES)
SHARED_PRECOMPS_DIR = $(HERE_INTERMEDIATES)/PrecompiledHeaders
SYMROOT = $(HERE_BUILD)/Products
When I changed HERE_BUILD to have absolute path:
HERE_BUILD=$(SRCROOT)/Build-command-line
the error went away.