Get top 10 cities per country
Hi
I am trying to fetch top 10 cities by population for countries listed in the IN clause.
select * from (
Select city_name, population...
from test
where country in ('China','India', 'USA')
order by population
where rownum <=10.
What I need as an output is total of 30 rows in this case, 10 for India, 10 for US and 10 for China.
What am I doing wrong here? I get more rows.
Any help appreciated.
Thx!
You didn't specify a version.
I am assuming one with analytics available
DROP TABLE CITIES;
CREATE TABLE CITIES
(COUNTRY VARCHAR2(30)
,CITY VARCHAR2(30)
,POPULATION NUMBER
INSERT INTO CITIES (COUNTRY,CITY,POPULATION)
SELECT
'COUNTRY'||FLOOR(DBMS_RANDOM.VALUE(1,4)) COUNTRY
,'CITY'||ROWNUM CITY
,TRUNC(DBMS_RANDOM.VALUE(200,35000000) ) POPULATION
FROM
DUAL
CONNECT BY LEVEL <= 200
COMMIT;
SELECT
COUNTRY
,CITY
,POPULATION
,RANKING
FROM
SELECT
COUNTRY
,CITY
,POPULATION
,RANK() OVER (PARTITION BY COUNTRY ORDER BY COUNTRY,POPULATION) RANKING
FROM
CITIES)
WHERE
RANKING <=10
ORDER BY COUNTRY,RANKING DESC;
COUNTRY CITY POPULATION RANKING
COUNTRY1 CITY122 4858897 10
COUNTRY1 CITY133 4819304 9
COUNTRY1 CITY73 4045273 8
COUNTRY1 CITY101 3285468 7
COUNTRY1 CITY90 3222442 6
COUNTRY1 CITY142 2996082 5
COUNTRY1 CITY70 2799399 4
COUNTRY1 CITY49 2459511 3
COUNTRY1 CITY99 914365 2
COUNTRY1 CITY100 209141 1
COUNTRY2 CITY16 5825305 10
COUNTRY2 CITY195 5152174 9
COUNTRY2 CITY63 5017615 8
COUNTRY2 CITY165 5010887 7
COUNTRY2 CITY42 4267026 6
COUNTRY2 CITY50 3255312 5
COUNTRY2 CITY115 3048442 4
COUNTRY2 CITY176 2172578 3
COUNTRY2 CITY79 1815271 2
COUNTRY2 CITY4 1039363 1
COUNTRY3 CITY44 3094211 10
COUNTRY3 CITY45 3037433 9
COUNTRY3 CITY15 2472461 8
COUNTRY3 CITY36 1710581 7
COUNTRY3 CITY131 1346831 6
COUNTRY3 CITY192 1289185 5
COUNTRY3 CITY92 894559 4
COUNTRY3 CITY68 638714 3
COUNTRY3 CITY61 299477 2
COUNTRY3 CITY157 227579 1
30 rows selected.
Similar Messages
-
How many users per country and their names and cities in abap ?
Hi,
i want to build a list of my users on PRD per country and their names in an abap programm.
Do you have any code for that ! Will be pleased to hear from you.
Thanks
Kumar
Moderator Message: You might be a Basis chap, but that doesn't mean we will do your work for you. Take the help of a ABAPer and get it done.
Edited by: kishan P on Nov 21, 2010 6:42 PMHi,
i am just looking for an abap code as i am not a developer. I am a basis chap, i searched in sapnet, but nothing of the sort i am looking for. All RSUSRXXX reports are of general nature. Will be pleased to hear from ABAPERS or basis guyes who have
faced this problem and solved.
Thanks in adv.
Kumar/Germany -
Current Quantity per Country of Origin
Hi Guys
this is my first post and I hope that I get some orientations from your experiences
We have a requirement to provide (within a report or whatever) the current and real quantity of each material per country of origin (the origin of material supplier).. in other words, how can we calculate the current quantity available per material per plant, taking into account (for each material) the:
inbound delivery (from the supplier)
sales order
outbound delivery
the origin of the material
Example:
From For coutry of origin US, for material ABCD, the current quantity today is: 25 (taking into account the in-progress: PO & inbound delivery & sales order & oubound delivery)
Thank you
Appreciate your support
RegardsHello,
Country of Origin can be maintained in Info Record (ME11/ME12) at Vendor/Material level. This can be used while outputting the Purchase orders.
Thanks,
Venu -
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 -
Where can i get top games for my macbook pro retina
is there anyway i can get top games that can be played on my macbook apart from those from the app world
or anything i can purchase that can helpApple has installed a security feature called Gatekeeper that restricts software being installed from only Apple developers, so sometimes you will need to bypass this by Control key or right mouse clicking on the installer or program and selecting "Open".
A warning comes up about software from unsigned developers, but if you trust the source of the software then allow it.
Also because Apple releases a new OS X version every year, it's rather difficult for developers to keep up especially with very complex games.
So if you see a "download" and go ahead and purchase it, you might find out later it can't run on your machine.
So do your home work and ask around to make sure the game/software your installing is going to be compatile with your OS X version.
Since Apple just released a update for 10.8, it might have broken some games, so check to see if their are any compliants from other users before installing.
Just remmeber if Apple releases another OS X upgrade, that it very well can break your presently installed games.
It's up to the developer if they are going to bother to make a update, they may decide they spent enough money and can't afford to upgrade the program for the newer OS X verison.
So you will have to keep this in mind BEFORE you upgrade OS X, to wait for all your third party software to have updated versions before you upgrade OS X to a new version.
In my opinion, Apple does everything possible to make life hard for Mac users, especially gamers.
I think our much better off on a Windows 3D tower where Windows remains supported for about 10 years just like it is and you can find video cards everywhere.
Good Luck -
I'm trying to create a mail merge label sheet and am getting one label per page- how do I get each on entry on same sheet?
Is there a "next entry" code?select phase_logid, orderid, phaseid, etc, max(statusid)
status
from yourtables
where whatever
group by phase_logid, orderid, phaseid, etc -
If I add artwork by dragging a jpg to the artwork area after selecting several rows, in some instances a single icon is created in the flipper; in others one is created for each song. Why? How can I get one image per album every time?
If I add artwork by dragging a jpg to the artwork area after selecting several rows, in some instances a single icon is created in the flipper; in others one is created for each song. Why? How can I get one image per album every time?
-
To get top-of-page in alv list
How get top-of-page using reuse_alv_list_display ?
How to get checkbox into that top-of-page ? And how to access that checkbox whether it is checked or not ? And if checked to get into next step of program promptly ?hai Anirban Datta,
REPORT YBALV_FULLSCREEN_DEMO NO STANDARD PAGE HEADING.
*"General Data
TYPE-POOLS: SLIS.
DATA: BEGIN OF GT_OUTTAB OCCURS 0.
INCLUDE STRUCTURE SFLIGHT.
DATA: END OF GT_OUTTAB,
GS_LAYOUT TYPE SLIS_LAYOUT_ALV,
G_EXIT_CAUSED_BY_CALLER,
GS_EXIT_CAUSED_BY_USER TYPE SLIS_EXIT_BY_USER,
G_REPID LIKE SY-REPID.
*"Callback
DATA:
GT_EVENTS TYPE SLIS_T_EVENT,
GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER,
G_STATUS_SET TYPE SLIS_FORMNAME VALUE 'PF_STATUS_SET',
G_USER_COMMAND TYPE SLIS_FORMNAME VALUE 'USER_COMMAND',
G_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE',
G_TOP_OF_LIST TYPE SLIS_FORMNAME VALUE 'TOP_OF_LIST',
G_END_OF_LIST TYPE SLIS_FORMNAME VALUE 'END_OF_LIST'.
*"Variants
DATA: GS_VARIANT LIKE DISVARIANT,
G_SAVE.
INITIALIZATION.
G_REPID = SY-REPID.
PERFORM LAYOUT_INIT USING GS_LAYOUT.
PERFORM EVENTTAB_BUILD USING GT_EVENTS[].
GS_VARIANT-REPORT = G_REPID.
G_SAVE = 'A'.
START-OF-SELECTION.
*"Data Selection
PERFORM SELECT_DATA TABLES GT_OUTTAB.
END-OF-SELECTION.
*"List Header for Top-Of-Page
PERFORM COMMENT_BUILD USING GT_LIST_TOP_OF_PAGE[].
*"Display List
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_BACKGROUND_ID = 'ALV_BACKGROUND'
i_buffer_active = 'X'
I_CALLBACK_PROGRAM = G_REPID
I_STRUCTURE_NAME = 'SFLIGHT'
IS_LAYOUT = GS_LAYOUT
I_SAVE = G_SAVE
IS_VARIANT = GS_VARIANT
IT_EVENTS = GT_EVENTS[]
I_SCREEN_START_COLUMN = 0 "Use coordinates for
I_SCREEN_START_LINE = 0 "display as dialog box
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
IMPORTING
E_EXIT_CAUSED_BY_CALLER = G_EXIT_CAUSED_BY_CALLER
ES_EXIT_CAUSED_BY_USER = GS_EXIT_CAUSED_BY_USER
TABLES
T_OUTTAB = GT_OUTTAB
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC = 0.
IF G_EXIT_CAUSED_BY_CALLER = 'X'.
*" Forced Exit by calling program
*" <do_something>.
ELSE.
*" User left list via F3, F12 or F15
IF GS_EXIT_CAUSED_BY_USER-BACK = 'X'. "F3
*" <do_something>.
ELSE.
IF GS_EXIT_CAUSED_BY_USER-EXIT = 'X'. "F15
*" <do_something>.
ELSE.
IF GS_EXIT_CAUSED_BY_USER-CANCEL = 'X'. "F12
*" <do_something>.
ELSE.
*" should not occur!
*" <do_Abnormal_End>.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ELSE.
*"Fatal error callin ALV
MESSAGE AXXX(XY) WITH ...
ENDIF.
*"Form routines
FORM SELECT_DATA TABLES RT_OUTTAB LIKE GT_OUTTAB[].
*"- Selection of data to be displayed
SELECT * FROM SFLIGHT INTO CORRESPONDING FIELDS
OF TABLE RT_OUTTAB
UP TO 00030 ROWS.
ENDFORM.
FORM LAYOUT_INIT USING RS_LAYOUT TYPE SLIS_LAYOUT_ALV.
*"Build layout for list display
RS_LAYOUT-DETAIL_POPUP = 'X'.
ENDFORM.
FORM EVENTTAB_BUILD USING RT_EVENTS TYPE SLIS_T_EVENT.
*"Registration of events to happen during list display
DATA: LS_EVENT TYPE SLIS_ALV_EVENT.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = RT_EVENTS.
READ TABLE RT_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE
INTO LS_EVENT.
IF SY-SUBRC = 0.
MOVE G_TOP_OF_PAGE TO LS_EVENT-FORM.
APPEND LS_EVENT TO RT_EVENTS.
ENDIF.
ENDFORM.
FORM TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
I_LOGO = 'ENJOYSAP_LOGO'
IT_LIST_COMMENTARY = GT_LIST_TOP_OF_PAGE.
ENDFORM .
FORM COMMENT_BUILD USING LT_TOP_OF_PAGE TYPE
SLIS_T_LISTHEADER.
DATA: LS_LINE TYPE SLIS_LISTHEADER.
LIST HEADING LINE: TYPE H
CLEAR LS_LINE.
LS_LINE-TYP = 'H'.
LS_LINE-KEY: NOT USED FOR THIS TYPE
LS_LINE-INFO = TEXT-100.
APPEND LS_LINE TO LT_TOP_OF_PAGE.
STATUS LINE: TYPE S
CLEAR LS_LINE.
LS_LINE-TYP = 'S'.
LS_LINE-KEY = TEXT-101.
LS_LINE-INFO = TEXT-102.
APPEND LS_LINE TO LT_TOP_OF_PAGE.
LS_LINE-KEY = TEXT-103.
LS_LINE-INFO = TEXT-104.
APPEND LS_LINE TO LT_TOP_OF_PAGE.
ACTION LINE: TYPE A
CLEAR LS_LINE.
LS_LINE-TYP = 'A'.
LS_LINE-KEY: NOT USED FOR THIS TYPE
LS_LINE-INFO = TEXT-105.
APPEND LS_LINE TO LT_TOP_OF_PAGE.
ENDFORM.
Regards.
Eshwar. -
How to get top 10 employees in BEx Report
Hi all,
I am trying to get top 10 employees who have worked over 50 hrs of overtime in any pay period i choose in query.
How do i get it ??
right now my report gives me total of over 50hrs overtime in all chosen pay period employees list.
Any suggestions ??
Thank You,
KSmithCAN SOMEONE PLEASE HELP ME SOLVE THIS PROBLEM ??
Hi all,
The problem I have is even though i tried condition for top 10 employees who worked more than 50 hrs.
My report right now shows all employees overtime under "OT" key figure for each pay period. --> I just want to show employees and overtime which is > 50 for each different pay period
The condition works only if i display just one pay period...and user dont want it that way. they want to get more than one pay period displayed on the report and should have list of employees who work more than 50 hrs over time. HOW DO I GET THAT ??
Also there is another key figure count meaning if out of those chosen pay periods there are 3 periods when an employee worked more than 50 hrs of over time then it should show "3". if there 2 pay periods when employee work more than 50 hrs count should display 2 ---> right now i am not able to get that also.
Please can some one suggest something ??
Thank You,
KSmith
Edited by: Keral Smith on Jul 25, 2008 2:49 PM
Edited by: Keral Smith on Jul 25, 2008 3:08 PM -
Getting Top odf page in REUSE_ALV_HIERSEQ_LIST_DISPLAY List
Hi
I am using FM: REUSE_ALV_HIERSEQ_LIST_DISPLAY to display the list..
But i didn't get top of page on the same. Can any know abt the same please
give ans with sample code. I would appreciate your prompt help..
thanks,You have to use the EVENTS parameter in this case. Here is a complete example.
report zrich_0001 .
type-pools: slis.
data: begin of head occurs 0,
matnr type afpo-matnr,
maktx type makt-maktx,
expand type c,
end of head.
data: begin of detail occurs 0,
matnr type marc-matnr,
werks type marc-werks,
dispo type marc-dispo,
end of detail.
data: events type slis_t_event,
list_top_of_page type slis_t_listheader,
top_of_page type slis_formname value 'TOP_OF_PAGE'.
start-of-selection.
select matnr maktx from makt
into table head
up to 100 rows.
if not head[] is initial.
sort head ascending by matnr.
select matnr werks dispo into table detail
from marc
for all entries in detail
where matnr = detail-matnr.
endif.
perform call_alv.
* FORM call_alv *
form call_alv.
data: gt_fieldcat type slis_t_fieldcat_alv,
gs_keyinfo type slis_keyinfo_alv,
gs_layout type slis_layout_alv.
data: ls_fieldcat type slis_fieldcat_alv.
clear gs_keyinfo.
gs_keyinfo-header01 = 'MATNR'.
gs_keyinfo-item01 = 'MATNR'.
clear ls_fieldcat.
ls_fieldcat-fieldname = 'MATNR'.
ls_fieldcat-reptext_ddic = 'Material'.
ls_fieldcat-tabname = 'HEAD'.
ls_fieldcat-outputlen = 18.
append ls_fieldcat to gt_fieldcat.
clear ls_fieldcat.
ls_fieldcat-fieldname = 'MAKTX'.
ls_fieldcat-reptext_ddic = 'Description'.
ls_fieldcat-tabname = 'HEAD'.
ls_fieldcat-outputlen = 40.
append ls_fieldcat to gt_fieldcat.
clear ls_fieldcat.
ls_fieldcat-fieldname = 'WERKS'.
ls_fieldcat-reptext_ddic = 'Plant'.
ls_fieldcat-tabname = 'DETAIL'.
ls_fieldcat-outputlen = 4.
append ls_fieldcat to gt_fieldcat.
clear ls_fieldcat.
ls_fieldcat-fieldname = 'DISPO'.
ls_fieldcat-reptext_ddic = 'MRP Controller'.
ls_fieldcat-tabname = 'DETAIL'.
ls_fieldcat-outputlen = 5.
append ls_fieldcat to gt_fieldcat.
gs_layout-expand_fieldname = 'EXPAND'.
perform eventtab_build using events[].
perform comment_build using list_top_of_page[].
data: repid type sy-repid.
repid = sy-repid.
call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
exporting
i_callback_program = repid
it_fieldcat = gt_fieldcat[]
is_layout = gs_layout
i_tabname_header = 'HEAD'
i_tabname_item = 'DETAIL'
it_events = events[]
is_keyinfo = gs_keyinfo
tables
t_outtab_header = head
t_outtab_item = detail.
endform.
* EVENTTAB_BUILD
form eventtab_build using events type slis_t_event.
* Registration of events to happen during list display
data: tmp_event type slis_alv_event.
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events = events.
read table events with key name = slis_ev_top_of_page
into tmp_event.
if sy-subrc = 0.
move top_of_page to tmp_event-form.
append tmp_event to events.
endif.
endform.
* COMMENT_BUILD
form comment_build using list_top_of_page type
slis_t_listheader.
data: tmp_line type slis_listheader.
clear tmp_line.
tmp_line-typ = 'H'.
tmp_line-info = 'Here is a line of text'.
append tmp_line to list_top_of_page.
clear tmp_line.
tmp_line-typ = 'S'.
tmp_line-key = 'Key1'.
tmp_line-info = 'Here is a value'.
append tmp_line to list_top_of_page.
clear tmp_line.
tmp_line-typ = 'S'.
tmp_line-key = 'Key2'.
tmp_line-info = 'Here is another value'.
append tmp_line to list_top_of_page.
endform.
* TOP_OF_PAGE
form top_of_page.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
* i_logo = 'ENJOYSAP_LOGO'
it_list_commentary = list_top_of_page.
endform.
Regards,
RIch Heilman -
Hello. I have a problem with my Photoshop Elements 12 programm. I had restart my computer and I wanted to instal my Photoshop Elements 12 again but the sytem didn't accept my serial number. I get no answer per Mail and I didn't reach someone on my phone. Can you help me please? Thanks a lot Nana
1) Apps are not part of the backup, only data stored by 3rd party apps. But you can redownload the apps for free again if you use the same account you did when you bought them the first time. http://support.apple.com/kb/HT2519
2) See this article http://support.apple.com/kb/HT1766 and find out what's in your backup.
3) Backup your itunes+ library (http://support.apple.com/kb/HT1382 and http://support.apple.com/kb/HT1751), which will copy your Mobile Applications folder, and save your iphone backup folder as well
In other words, maintaining a backup of your computer is essential.
When you resync your apps from your computer to the phone, make sure your computer is authorized again. http://support.apple.com/kb/HT1420 -
See Inventory Organization Hierarchy, getting error APP-PER-50022
Hi friends
i need to see Inventory Organization Hierarchy. whenever i click Hierarchy in Inventory responsibility i get error APP-PER-50022. It says
Oracle Human Resource could not retrieve a value for the user type profile option. Please ensure it is it set property for your responsibility.
i have System Administrator responsibility. pls tell me what to do.
thanks in advancePl set the profile option "HR : User Type" - see MOS Doc 604432.1 (Error while setting up Inventory Organization)
HTH
Srini -
How can I get Top Sites to open full screen?
How can I get Top Sites to open full screen?
http://support.apple.com/kb/PH11881
System Preferences > General
Uncheck the box beside "Close windows when quitting an application". -
How to get 'Top Sites' back?
I downloaded an Installer, but then deleted it, however what i didn't notice was that it had made itself my Safari Homepage, rather than 'Top Sites', how do i get 'Top Sites' back?
Open Safari and click Preferences on the menu named Safari. On the General tab set "New Windows Open with" and "New Tabs Open with" to Top Sites. It doesn't matter what the Homepage is set to if the above are set to Top Sites.
If New Windows Open With isn't a choice, go to Apple Menu > System Preferences > General and put a checkmark in front of "Close Windows when Quitting an app." -
How to get top left stage corner coordinates after resize?
hi,
is there maybe a way to get top left stage corner coordinates
after resize?
or maybe get original stage size before resize? so i can
calculate it.
i know that you can collect the width and height before it is
resized but is it possible after?
--- sorry for the double post ---i donno exactly but try like this ,
data: i_logo type bds_typeid.
data: lr_logo type ref to cl_salv_form_layout_logo,
lr_content type ref to cl_salv_form_element.
i_logo = 'MY_SAP_LOGO'.
IF i_logo is not initial.
create object lr_logo.
lr_logo->set_left_content( i_logo ).
lr_content = lr_logo.
endif.
cl_salv_form_content=>set( lr_content ).
Maybe you are looking for
-
Calling WebDynpro Application and Passing parameters
Hi, I want to call a webdynpro application from another application and also i want to pass parameters to the called webdynpro application. Is there an example on SDN which shows how this can be done. If not please advise how this can be done. Thanks
-
Changing ipod from windows to Mac
I am having a lot of trouble for my new mac computer to recgnize my old ipod that was formatted in windows. Do you know how to do this so that i can later recover the music that i previously had saved there and pass it on to my mac?
-
Updating touch to 4.3.1
I am having problems updating 16gb ipod touch to 4.3.1 when I connect to i tunes it says that 4.2.1 is latest software update. Any ideas or solutions?
-
I have downloaded Adobe Muse to CC, but are unable to open. Why?
I have downloaded Adobe Muse to CC, but are unable to open. Why?
-
How to delete safari virus programs
how to delete safari virus programs from the publicity videos software