Get count of officers for each company
Hi, all. I need to get the count of officers from each company from the following data,
CompanyID OfficerID
1234 4456
1234 2087
1234 1298
7765 2376
9987 5423
9987 2965
What I need is the following for the above data,
CompanyID OfficerCount
1234 4
7765 1
9987 2
What SELECT will get me this data? Thank you.
Thanks, Dishoom! That worked like a charm! Been working on that problem, thinking it's going to require something complicated. You solved it in 3 lines. Thank :)
Similar Messages
-
How to get count of records for each type from internal table
Hi Guys,
I want to implement a logic to find out the count of records in a internal table.
Assume my internal table have one field having the entries as shown below.
Internal table Entries
10
10
10
11
11
12
12
12
12
13
14
14
15
15
15
15
15
16
16
17
18
19
20
20
20
....... etc....
I should get an output as below
10's - 3
11's -2 ,
12's - 4.... etc..
Could any one help me how to do this.
Thanx,
KumarREPORT zzz.
DATA: i(100),
t(100),
j TYPE n.
TYPES: BEGIN OF gt_int_type,
linex(100) TYPE c,
END OF gt_int_type.
DATA: gt_int TYPE STANDARD TABLE OF gt_int_type,
wa_int LIKE LINE OF gt_int.
START-OF-SELECTION.
wa_int-linex = '10'.
APPEND wa_int TO gt_int.
wa_int-linex = '10'.
APPEND wa_int TO gt_int.
wa_int-linex = '10'.
APPEND wa_int TO gt_int.
wa_int-linex = '11'.
APPEND wa_int TO gt_int.
wa_int-linex = '11'.
APPEND wa_int TO gt_int.
wa_int-linex = '12'.
APPEND wa_int TO gt_int.
wa_int-linex = '12'.
APPEND wa_int TO gt_int.
wa_int-linex = '12'.
APPEND wa_int TO gt_int.
wa_int-linex = '12'.
APPEND wa_int TO gt_int.
wa_int-linex = '13'.
APPEND wa_int TO gt_int.
wa_int-linex = '14'.
APPEND wa_int TO gt_int.
wa_int-linex = '14'.
APPEND wa_int TO gt_int.
wa_int-linex = '15'.
APPEND wa_int TO gt_int.
wa_int-linex = '15'.
APPEND wa_int TO gt_int.
wa_int-linex = '15'.
APPEND wa_int TO gt_int.
wa_int-linex = '15'.
APPEND wa_int TO gt_int.
wa_int-linex = '15'.
APPEND wa_int TO gt_int.
wa_int-linex = '16'.
APPEND wa_int TO gt_int.
wa_int-linex = '16'.
APPEND wa_int TO gt_int.
wa_int-linex = '17'.
APPEND wa_int TO gt_int.
wa_int-linex = '18'.
APPEND wa_int TO gt_int.
wa_int-linex = '19'.
APPEND wa_int TO gt_int.
wa_int-linex = '20'.
APPEND wa_int TO gt_int.
wa_int-linex = '20'.
APPEND wa_int TO gt_int.
wa_int-linex = '20'.
APPEND wa_int TO gt_int.
LOOP AT gt_int INTO wa_int.
WRITE:/ wa_int-linex.
ENDLOOP.
ULINE.
SKIP 3.
SORT gt_int BY linex.
READ TABLE gt_int INDEX 1 INTO i.
j = 0.
LOOP AT gt_int INTO wa_int.
IF wa_int-linex EQ i.
j = j + 1.
ELSE.
WRITE:/ i,'''s = ', j.
j = 1.
i = wa_int-linex.
ENDIF.
ENDLOOP.
WRITE:/ i,'''s = ', j.
consider clearing leading/trainling spaces... -
If you registrate one Apple ID for each iPhone/iPad, you'll get 5GB on iCloud for each Apple ID, right? I have two iPhones and one iPad with the same Apple ID, why can't I get 5 GB fo each of them?
Actually, everyone missed one point, when a device is priced, the cost of icloud storage space for that device is also included in it that is why they are able to give you 5gb each for each user ID, in nutshell there is nothing free coming with apple device purchase, it is paid for. What they are trying by giving only 5gb per user ID irrespective of the number of devices used is pure broadlight looting, they take money from you when you buy each device and give you nothing, This is a case of goods and services bought but not fully deliverd ie apple can be suied for discreminatory treatment towards it's users. I wonder why no one tried this yet in America where everyone sue everyone for petty things..... there is no one to take up this issue? . if tim got any love for the guys who shell out money for the devices his company makes, he should be implimenting this as priority before someone wake up from sleep and sue him.
-
How to get all GL accounts for each account in a given bank...
Hello Experts,
Is there a way to get all GL accounts for each account in a given house bank?
IN our company, there are 5 GL accounts for each bank so 1 GL for 1 account. they are for recon, payables,
receivables, etc. I checked table T012K but it only shows the main GL account. Hope you
can help me guys. Thank you and take care!Try this.. it is based on company code
here it_cocodes is an internal table containing company codes
DATA: BEGIN OF it_glaccount OCCURS 0,
bukrs TYPE bukrs,
saknr TYPE saknr,
txt50 TYPE txt50_skat,
END OF it_glaccount.
DATA it_glaccount_wa LIKE it_glaccount.
LOOP AT it_cocodes INTO it_cocodes_wa WHERE ktopl <> ''.
SELECT bukrs saknr FROM skb1
INTO CORRESPONDING FIELDS OF it_glaccount_wa
WHERE bukrs = it_cocodes_wa-bukrs.
IF sy-subrc = 0.
SELECT SINGLE txt50 FROM skat INTO it_glaccount_wa-txt50
WHERE spras = 'E' AND ktopl = it_cocodes_wa-ktopl
AND saknr = it_glaccount_wa-saknr.
APPEND it_glaccount_wa TO it_glaccount.
CLEAR it_glaccount_wa-txt50.
ENDIF.
ENDSELECT.
loop at it_glaccount into it_glaccount_wa.
write:/....
endloop.
refresh...
clear...
endloop. -
How do I get separate iCloud accounts for each family members device and still share iTunes?
how do I get separate iCloud's for each family members iPhone, iPod and iPad and still share iTunes?
Have everyone share the same iTunes store ID, but use separate IDs for iCloud. The ID you use for iCloud does not have to be the same as the ID you use for the iTunes & App store.
-
Getting the first row for each group
Hi Everyone,
I have a query which returns a number of rows, all of which are valid. What I need to do is to get the first row for each group and work with those records.
For example ...
client flight startairport destairport stops
A fl123 LGW BKK 2
A fl124 LHR BKK 5
B fl432 LGW XYZ 7
B fl432 MAN ABC 8
.... etc.
I would need to return one row for Client A and one row for Client B (etc.) but find that I can't use the MIN function because it would return the MIN value for each column (i.e. mix up the rows). I also can use the rownum=1 because this would only return one row rather than one row per group (i.e. per client).
I have been investigating and most postings seem to say that it needs a second query to look up the first row for each grouping. This is a solution which would not really be practical because my query is already quite complex and incorporating duplicate subqueries would just make the whole thing much to cumbersome.
So what I really new is a "MIN by group" or a "TOP by group" or a "ROWNUM=1 by group" function.
Can anyone help me with this? I'm sure that there must be a command to handle this.
Regards and any thanks,
Alan Searle
Cologne, GermanySomething like this:
select *
from (
select table1.*
row_number() over (partition by col1, col2 order by col3, col4) rn
from table1
where rn = 1In the "partition by" clause you place what you normally would "group by".
In the "order by" clause you define which will have row_number = 1.
Edit:
PS. The [url http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/functions004.htm#i81407]docs have more examples on using analytical functions ;-)
Edited by: Kim Berg Hansen on Sep 16, 2011 10:46 AM -
How to get top 10 records for each option in table prompt?
Hi,
I have created one report in which my requirement is to get top 10 highest salaries for each departments. I have created one table prompt which contains the names of all departments. On the salary column I have applied one filter i.e. TOP 10. Currently I am having 3 departments. I want to show the top 10 salaries for each department, but I am getting top 3 from first, 4 from second and 3 from third.They are calculating top 10 salaries based on all departments, not on individual department. How can I get top 10 salaries for each department?Hi,
Use TopN function in your column formula.
Ex: TOPN("Sales ,5 BY department)
Thanks,
Satya -
How to get count of rows for a table?
Hi,
How to get count of rows for a table and secondly, how can i have access to a particular cell in a table?
Regards,
DevashishHi Devashish,
WdContext.node<Your_node_name>().size() will give you the no: of rows.
This should be the node that is bound to the table's datasource property.
WdContext.node<Your_node_name>().get<node_name>ElementAt(index_value); will select the row at that particular index.
You can access an attribute of a particular row as
WdContext.node<Your_node_name>().get<node_name>ElementAt(index_value).get<attribute_name>();
Hope this helps,
Best Regards,
Nibu.
Message was edited by: Nibu Wilson -
How to get count as 0 for records not in table
Hi All,
I have requirement where I need count of records in the table based on ids. Example query below
SELECT empid ,
nvl(COUNT(id), 0) empcount
FROM employee
WHERE empid IN(1, 2, 4, 5)
GROUP BY empid
In the table only record for "empid=2" is present so I get count 1 for it. But with it I should get count as 0 for non existing records. Expecting below output
empid | empcount
1 | 0
2 | 1
4 | 0
5 | 0
Appreciate your help and Thanks in advance.
Regards.
Ashishe.g.
SQL> select column_value deptno, count (deptno)
from emp, table (sys.odcinumberlist (10, 20, 100))
where deptno(+) = column_value
group by column_value
DEPTNO COUNT(DEPTNO)
10 3
20 5
100 0
3 rows selected. -
How to get Privacy Policy value for each userprofile in sharepoint 2010?
In userprofile application, we have defined Privacy Policy of mobilephone feild as optional, so every user has option to choose visibility scope of this property to "Everyone/My Manager/my colegues/Only Me" .
Now I am trying to get mobilephone value and their selected visibility option for each user.
I am able to get mobilephone value but I could not get "what each user has chosen as their visibility scope"?Hi,
According to your post, my understanding is that you want to get Privacy Policy value for each userprofile in sharepoint 2010.
You need to use RunWithElevatedPrivileges method to impersonate user.
To get the get mobilephone policy, you can use user["CellPhone "].Privacy.
For more information, you can refer to:
c# - Getting property privacy with Sharepoint 2010
How to Programmatically Impersonate Users in SharePoint
Managing Sharepoint 2010 Profiles Programmatically
Thanks,
Linda Li
Forum Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
[email protected]
Linda Li
TechNet Community Support -
How to get multiple output formats for each execution of the report?
Hi,
Is it possible to get multiple output formats for each execution of the report? If so can you provide some details?
ThanksIn Reports 6i, Reports Distribution was introduced. This allows you to run the report once and output to a number of destinations with a different format. It also allows you to distribute individual sections within a report to different destinations in different formats.
The Destinations for a Report to distribute to are defined either in a distribution file and passed on the command line or inside of the report definition.
To add a destination to the the report definition, bring up the property palette against the report object and then select the "Distribution" property under the "Report" node. This will bring up a dialog that allows you to create a distribution list. You can then test this list by selecting "file->distribute" from the menu.
To run a report that is to be distributed through rwrun60, you need to add "distribute=yes" to the command line. It will pick up the destinations from the report definition. If you add "destination=<filename>" then it will pick up the destinations from the specified "<filename>" and ignore the destinations in the report definition.
Note: if "distribute=yes" is specified on the command line then the destype/desname/desformat parameters will be used to format the report (ie: which printer/display to use during formatting for sizing objects) but will be ignored when the report is sent to the destinations. -
Firefox will not show links to flv files. I get the error message for each flv file: "File not found. Firefox can't find the file at http:// (path) .flv." Any mov and swf files in this same path will show. I can see the videos in Safari so the paths are correct.
Is this a webpage that contains a link to a flv file? Please post a link to the page and tell us which link(s) are the problem flv files or else post a link to the .flv file itself.
Alternately, click on one of the sample FLV File links on this page and tell us exactly what happens:
http://www.mediacollege.com/adobe/flash/video/tutorial/example-flv.html
It might also help if you post the exact error message, including the path to the flv file.
'''Note:'''
Depending on how you have Firefox set up, clicking on a FLV File link will either save the FLV file to your computer or Firefox may open it automatically in an external application right after downloading (Firefox may ask you first). Firefox itself can't play FLV files so you need a "helper" application (or a plugin for flv files, if ther is one. You can see if Firefox is already set up to download or open FLV files by going to Firefox Preferences and looking in the Applications list. Find the FLV file type in the list and, if the action is "Open with", it should show the application that can play FLV files (e.g., VLC Media Player or Perian). See [[Managing filetypes]] for more information. -
How to get the time interveral for each status of worklow (wating,Inprocess
Hi Friends,
I have requreiemnt to get the time interval for each status of workflow.
ex.
status
workflow id | startd date | enddate | waiting | Inprocessing|Error|......
1026 10.10.2008 25.10.2008 1hr 1hr 30 min 2 hr
Please do give me idea how to get the time stam of each status of workflow.
Thanks,
D.prabhuHi,
I think the following tables would be helpful to you:-
SWW_CONT Container Contents for Work Item Data Container
SWW_CONTOB "Container Cont. for Work Item Data Container (Only Objects)"
SWWLOGHIST History of a work item
SWWORGTASK Assignment of WIs to Org.Units and Tasks
SWWUSERWI Current Work Items Assigned to a User
SWWWIHEAD Header Table for all Work Item Types
Hope it Helps!
Regards,
Kanika -
Can it be a seperate cost component structure for each company code?
Company Code No 1 Setting:
Company Code XXXX with Chart of accounts X(Quantity + Value updation in material type)
In the existing company code(XXXX) ,Cost component structure is defined as
All company code---->All Plants----> All Costing Variants -
>Cost component Structure AA
Company Code No 2 Setting:
Scenario:
Now I am creating a new company Code YYYY) which is is allowed for quantity updation alone and trying to create a product cost collector to carry out Production confirmation through Repetetive manufacturing (."Error = Cost object component split costed with Value of Zero"
Can it be possible to have a seperate cost component structure for each company Code?
Company Code YYYY with Chart of accounts Y which is different from Company code 1(Quantity alone in material type)
If possible ,Can anybody provide a procedure to do the configuration of Cost Component structureHello,
As I understand your question, All the thing which are releted to costing are done only at the controlling area level not at company code.
As your req diffrent cost componenet for diffrent company code is depend up on how you define the controlling area.
Hope it will clear you
Regards
Ravi -
Query to count ACTIVE records for each month
All,
I have a requirement to count the number of active customers for each month of an year. Let's say, we have 3 fields in the table:
ID ActiveStart ActiveEnd
1 1/1/2014 11/30/2014
In this scenario, the member with ID was active for all the months (Jan-November) EXCEPT, December. So, the result set I am expecting for the Month of January to December is like below:
Month CountOfMembers
Jan 1
Feb 1
Mar 1
April 1
May 1
June 1
July 1
August 1
Sept 1
Oct 1
Nov 1
Dec 0 (Since, the member was NOT active in this month)
Similarly, if you have another member whose start date is 1/1/2014 and termination is '5/31/2014', then, I would need to add 1 for months of January till May, the member WON'T be counted for the rest of the months. So, in this case, the count will be come
"2" for months January till May, it will remain "1" for June till November and still "O" for December.>>I have a requirement to count the number of active customers for each month of an year. Let's say, we have 3 fields [sic: columns are not fields] in the table [sic: tables have names]: <<
Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI-ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need to
know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI-ISO Standard SQL. And you need to read and download the PDF for:
https:--www.simple-talk.com-books-sql-books-119-sql-code-smells-
There is no magical universal “id” in RDBMS, tables have names and columns have constraints and types. Most of the work in SQL is done in the DDL. Here is a possible schema.
CREATE TABLE Duty_Roster
(member_nbr INTEGER NOT NULL PRIMARY KEY,
duty_start_date DATE NOT NULL,
duty_end_date DATE NOT NULL,
CHECK (duty_start_date <= duty_end_date),
INSERT INTO Duty_Roster
VALUES
(1, '2014-01-01', '2014-11-30'),
(2, '2014-01-01', '2014-05-31');
>> In this scenario, the member with ID was active for all the months (Jan-November) EXCEPT, December. So, the result set I am expecting for the Month of January to December is like below: <<
A month is a temporal measurement that makes no sense without a year. But if you knew the ISO temporal model, you would see that you have what is called an INTERVAL data type. T-SQL does not support it yet.
Since SQL is a database language, we prefer to do look ups and not calculations. They can be optimized while temporal math messes up optimization. A useful idiom is a report period calendar that everyone uses so there is no way to get disagreements in the DML.
The report period table gives a name to a range of dates that is common to the entire enterprise.
CREATE TABLE Month_Periods
(month_name CHAR(10) NOT NULL PRIMARY KEY
CHECK (month_name LIKE '[12][0-9][0-9][0-9]-[01][0-9]-00'),
month_start_date DATE NOT NULL,
month_end_date DATE NOT NULL,
CONSTRAINT date_ordering
CHECK (month_start_date <= month_end_date),
etc);
These report periods can overlap or have gaps. I like the MySQL convention of using double zeroes for months and years, That is 'yyyy-mm-00' for a month within a year and 'yyyy-00-00' for the whole year. The advantages are that it will sort with the ISO-8601
data format required by Standard SQL and it is language independent. The pattern for validation is '[12][0-9][0-9][0-9]-00-00' and '[12][0-9][0-9][0-9]-[01][0-9]-00'
SELECT M.month_name, COUNT(R.member_nbr) AS member_cnt
FROM Month_Periods AS M,
Duty_Roster AS R
WHERE M.month_start_date
BETWEEN R.duty_start_date AND R.duty_end_date
AND M.month_end_date
BETWEEN R.duty_start_date AND R.duty_end_date;
We had no business rules about partial months, so I guessed.
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL
Maybe you are looking for
-
When I try to print coupons at coupons.com and target.com, just to name two, I get a message saying they "We're unable to support coupon printing on your system at this time. The Coupon Print Activator is supported on Windows Operating Systems 2000,
-
Tricky SQL query... how to get all data in a single query?
create table employee_definition (def_id number, def_name varchar(50)); insert into employee_definition values (100, 'EMAIL'); insert into employee_definition values (200, 'MOBILE_PHONE'); insert into employee_definition values (300, 'HOME_PHONE'); S
-
Group membership on AD-bound server is not updating correctly
I have a 10.6.4 server that is bound to AD with Win2008 domain controllers. I am seeing group membership not update properly on this OS X server. If I type "id -p username" I don't get a full list of groups the user is a member of. If I launch Workgr
-
Standby database Error in applying archives
Hi All Environment: Oracle 8i Platform- HP-UX I have production database on HPUX box and standby database on anothe HPUX box. I am applying archive to standby everyday manually. In last week, I have added ney datafile webapp03 in Production database
-
Publishing does not clear cache on secondary node on the cluster
Hello, I am publishing assets from Management to Delivery. Delivery consists of 2 nodes, one of which is the publish destination for the management. So, after a publish, I could see the updated content on Delivery 1 (cs/Satellite) but Delivery 2 (cs/