Sorting based on count of rows
Hi all,
I have a problem at hand. A table BEERS looks as follows:
BEER_NAME QUANTITY PRIORITY
Budweiser 17 1
Budweiser 16 2
Corona 22 1
Heineken 9 1
Heineken 11 3
Guinness 15 2
Corona 2 2
Heineken 13 2Here, I would like to arrange Beers in cases based on priority.
No beer of different brand should go in the same case.
No beer with same brand with different priority should go in the same case.
The maximum number of bottles that can be accomodated in a case is 10.
I wish to have a query which gives the result as follows:
BEER_NAME QUANTITY PRIORITY
Budweiser 10 1
Budweiser 7 1
Budweiser 10 2
Budweiser 6 2
Corona 10 1
Corona 10 1
Corona 2 1
Heineken 9 1
Heineken 10 3
Heineken 1 3
Guinness 10 2
Guinness 5 2
Corona 2 2
Heineken 10 2
Heineken 3 2How would I get this?
oracle Database Version: Enterprise Edition 10.2.0.1
Regards,
...
SQL>WITH t AS (
2 SELECT 'Budweiser' BEER_NAME, 17 QUANTITY, 1 PRIORITY FROM DUAL UNION ALL
3 SELECT 'Budweiser', 16, 2 FROM DUAL UNION ALL
4 SELECT 'Corona', 22, 1 FROM DUAL UNION ALL
5 SELECT 'Heineken', 9, 1 FROM DUAL UNION ALL
6 SELECT 'Heineken', 11, 3 FROM DUAL UNION ALL
7 SELECT 'Guinness', 15, 2 FROM DUAL UNION ALL
8 SELECT 'Corona', 2, 2 FROM DUAL UNION ALL
9 SELECT 'Heineken', 13, 2 FROM DUAL),
10 q AS
11 (SELECT MAX(quantity) AS maxq
12 FROM t)
13 SELECT BEER_NAME, LEAST(quantity + 10 - l * 10, 10) AS case_quantity, PRIORITY
14 FROM t,
15 (SELECT LEVEL AS l
16 FROM q
17 CONNECT BY LEVEL <= CEIL(maxq / 10))
18 WHERE l <= CEIL(QUANTITY / 10)
19 ORDER BY 1, 3, 2 DESC;
BEER_NAME CASE_QUANTITY PRIORITY
Budweiser 10 1
Budweiser 7 1
Budweiser 10 2
Budweiser 6 2
Corona 10 1
Corona 10 1
Corona 2 1
Corona 2 2
Guinness 10 2
Guinness 5 2
Heineken 9 1
Heineken 10 2
Heineken 3 2
Heineken 10 3
Heineken 1 3Urs
Similar Messages
-
Count MySQL rows based off Value in Dynamic Table
Greetings all. I have 2 MySQL tables; 1 that contains the names of my classes.(Class A, Class, B, etc.) and 1 table that contains the names of students in each Class (for example Class A: John Doe; Class A: Susie Smith.; Class B: Jane Doe). In the 2nd table the Class name is in its own column and the student's name is in a 2nd column.
I currently have a dynamic repeating table that lists the names of all of the classes from the 1st table. What I'm trying to do is add a second column to this repeating dynamic table that lists the number of students in each class. For example; Row 1 of the dynamic table would say "Class A | 5; Class B | 3; Class C | 7, etc.). The dynamic table works perfectly to list the class names. For the life of me I can't figure out how to perform a count for each class to insert in the repeating table. I will be adding more Classes which as why I'm trying to set up the counting query dynamically. So far I have only been able to figure out how to count the total rows in the 2nd table, or count the rows with a specified class name. Any advice or guidance on how to count the number of rows in the 2nd MySQL table based off the class name in the repeating table is much appreciated. Thank you for any and all help. Have a great day.Select count(*), Class from MyTable
Group by Class
Time to learn about SQL:
http://www.w3schools.com/sql/sql_intro.asp -
Sorting based on a specific value in Columns
Hi All,
Crystal 2008 version I have. And we are connecting to BW queries as source.
In a crosstab, I want to sort my row values based on a column value.
For example, in rows I have an element with three values . In column I have only one element(month), with couple of month values. My requirement is to sort rows based on a specific month (Mar'09 for example).
.....................Jan'09......Feb'09.....Mar'09
ABC...............10.............323...........33....
XYZ...............32..............33............11....
FGH...............5................34.............55...
But when I try to sort based on the Month, I can not select a specific value(mar'09). And it sorts based on the total value (sum of all months).
How can I achieve this problem?
Thanks
OzanFor {Sort Value}, if you wanted to sort on the Jan column, then substitute the field name that your example shows as 10 in row ABC. For {row value}, substitute the field name that is used in the first column (ABC in the example).
In other words, take the value that you want to sort on, and put it in front of the value currently displaying as the row header. Then, sort on the results.
The purpose of the "000000000.00" is to make the length of the number, when converted to string, a consistent size. This is needed (a) so you know how many characters to strip off when displaying the row value, and (b) so the records don't sort as 1, 12, 2, 234, 235423, 25, 3, ...
HTH,
Carl -
Is it possible to sort by word count
I have a list of titles and wish to arrange them by the number of words in each title, any suggestions gratefully received
Hi FF,
Word processing applications usually define a 'word' as a group of characters followed by a space (or a return).
I haven't foud a way to directly count the number of spaces in a string of text, but Numbers does support FIND() which can determine the position of a specific character's first appearance in a string or after a specified position in a string.
That's the method used in the coloured cells of the table below.
C2: =IFERROR(FIND(" ",$B,1+MAX($B2:B2)),"")
Fill right for as many cells as there are words in the 'longest' title.
Fill down to the end of the table.
A count of the cells containing numbers in the row (not including the cell in A, which must be a Header column) will give the number of spaces in the title. Add 1 for the number of words in the title.
A2: =IF(LEN(B)>0,COUNTIF(2:2,">0")+1,"")
Fill down to the last row in the table.
Sort on column A to arrange the titles by length in words.
Note the results in rows 5 and 6.
Row 5 contains the title of Paul Zindel's 1964 play as he wrote it. Man-in-the-Moon is considered as a single word in the count.
Row 6 contains the same title with the hyphens replaced by spaces. Man in the Moon now counts as 4 words.
Rows 7 and 8:
George Orwell's title is read as a number. As it's greater than 0, the number is included in the count. 1 is added to account for there being no space after the 'last word' in the title to give a count of 2. (Result is the same when the title is entered as '1984 (the leading ' tells Numbers, and other spreadsheets, to format the cell as text), of when the cell's format is set to Text using the Inspector.)
In row 8, 1984 is enclosed in quotation marks, and is now treated as text (with a numerical value of zero).
As noted, the columns doing the calculations may be hidden.
Regards,
Barry -
Hi!
I would like to get the count of rows in my ALV report . How to get the count of the rows ? Can anyone guide me in getting it dome please.
ThanksHi Gaddemmedi!
I am attaching the report as you had asked for. I have added the things you asked me to do and now I am getting the count on the top of the page. The problem is that though it shows me the count of the lines from the LAV report on top but when I try to filter the records in the report that count first of all dosent change and remain the same as the initial number of record though after filtering records reduce and over that the count lines keep on increasing I mean the count is shown in repeated lines afet lines. Kindly help please.
Thanks
*& Report ZSD_BILLING_HDR_TEXT_sum *
*& billing doc. and associated header text report *
*& CHANGE LOG *
*& jpoon 2007.08.03 Change request: DEVK905095 *
*& Move request: SD_1451_01 Requestor: Mona Fox *
*& FP14134 - original code. *
REPORT zsd_billing_hdr_text_sum MESSAGE-ID zsd NO STANDARD PAGE HEADING.
* For ALV usage
TYPE-POOLS: slis.
DATA: gs_layout TYPE slis_layout_alv,
tp_print TYPE slis_print_alv,
gt_sort TYPE slis_t_sortinfo_alv,
gt_events TYPE slis_t_event,
t_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
repid TYPE syrepid, " ABAP Program.
gt_list_top_of_page TYPE slis_t_listheader, " Top of page text.
alv_variant TYPE disvariant," Customize Disp. Variant
w_event type slis_alv_event.
DATA: w_field TYPE slis_fieldcat_alv.
TABLES: vbrk, vbrp, vbpa.
DATA SLIS_EV_AFTER_OUTPUT.
data: gs_list_top_of_page type slis_listheader.
*data: gt_list_top_of_page type slis_t_listheader.
* Definition of selection screen *
* By plant, storage location, sold-to customers, material and *
* posting date of the sales orders *
SELECTION-SCREEN BEGIN OF BLOCK one WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_vbeln FOR vbrk-vbeln, " billing doc.
s_kunnr FOR vbpa-kunnr, " bill-to customer number.
s_werks FOR vbrp-werks, " line item plant.
s_fkdat FOR vbrk-fkdat, " billing date.
s_fkart FOR vbrk-fkart, " billing type.
s_vkorg FOR vbrk-vkorg. " sales org.
PARAMETERS: p_hold AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK one.
* ALV display layout
SELECTION-SCREEN BEGIN OF BLOCK layout WITH FRAME TITLE text-003.
PARAMETERS: pa_vari TYPE slis_vari DEFAULT ' '. " Display variant.
SELECTION-SCREEN END OF BLOCK layout.
* Data Definitions *
* Storing Extracted Info.
TYPES: BEGIN OF t_extract,
vbeln TYPE vbeln_vf, " Sales order number.
posnr TYPE posnr, " line item
fkart TYPE fkart, " billing type.
vtext TYPE BEZEI20, " billing type description.
fkdat TYPE fkdat, " billing date.
werks TYPE werks_d, " line item plant.
werks_name1 TYPE name1, " plant description.
kunnr TYPE kunnr, " bill-to customer.
kunnr_name1 TYPE name1_gp, " bill-to description.
netwr TYPE netwr, " net value,invoice total $
zzflag TYPE boolean, " hold indicator
zzreason TYPE char30, " header text2 (reason)
zzuser TYPE ernam, " last changed by
zz_changed_date TYPE dats, " last changed date
zz_changed_time TYPE tims, " last changed time
END OF t_extract.
DATA: it_extract TYPE TABLE OF t_extract WITH HEADER LINE,
it_extract2 TYPE TABLE OF t_extract WITH HEADER LINE.
DATA: it_text TYPE TABLE OF tline WITH HEADER LINE.
DATA: wa_thead type thead.
DATA: w_tdname type TDOBNAME.
DATA: L_COUNT TYPE I.
* initialization
INITIALIZATION.
gs_layout-colwidth_optimize = 'X'.
tp_print-no_print_listinfos = 'X'.
tp_print-no_coverpage = 'X'.
PERFORM set_fieldcat.
PERFORM alv_eventtab_build USING:
** Event name Form to execute Event internal table
'TOP_OF_PAGE' 'TOP_OF_PAGE' gt_events[].
* Dropdown list for all created ALV layouts, global or user-specific
AT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_vari.
PERFORM alv_variant_f4 CHANGING pa_vari.
* Main BODY of processing logic
START-OF-SELECTION.
IF s_vbeln IS INITIAL
AND s_kunnr IS INITIAL
AND s_werks IS INITIAL
AND s_fkdat IS INITIAL
AND s_fkart IS INITIAL
AND s_vkorg IS INITIAL.
MESSAGE i000 WITH text-037 ' ' ' ' ' '.
ELSE.
PERFORM extract_data.
ENDIF.
END-OF-SELECTION.
IF it_extract2[] IS INITIAL.
MESSAGE i000 WITH text-002 ' ' ' ' ' '.
ELSE.
* Build headings for report.
* PERFORM build_top_of_page USING gt_list_top_of_page[].
* describe table it_extract2 lines l_count.
*write :/ 'TOTAL NO OF ENTRIES', SY-VLINE, 32 L_COUNT.
PERFORM call_alv.
*write :/ 'TOTAL NO OF ENTRIES', SY-VLINE, 32 L_COUNT.
ENDIF.
*& Form EXTRACT_KEY_DATA
* Retreive the data for the report.
FORM extract_data.
CLEAR: it_extract. REFRESH: it_extract.
* read and select billing documents
IF p_hold IS INITIAL.
SELECT vbrk~vbeln vbrk~fkart vbrk~fkdat vbrk~netwr
vbrk~zzflag vbrk~zzreason vbrk~zzuser
vbrk~zz_changed_date vbrk~zz_changed_time
vbrp~posnr vbrp~werks
INTO CORRESPONDING FIELDS OF TABLE it_extract
FROM vbrk INNER JOIN vbrp ON
vbrk~vbeln = vbrp~vbeln
WHERE vbrk~vbeln IN s_vbeln
AND vbrk~fkart IN s_fkart
AND vbrk~fkdat IN s_fkdat
AND vbrk~vkorg IN s_vkorg
AND vbrk~fksto NE 'X'
AND vbrp~werks IN s_werks.
ELSE.
* read 'held' documents only as per selection
SELECT vbrk~vbeln vbrk~fkart vbrk~fkdat vbrk~netwr
vbrk~zzflag vbrk~zzreason vbrk~zzuser
vbrk~zz_changed_date vbrk~zz_changed_time
vbrp~posnr vbrp~werks
INTO CORRESPONDING FIELDS OF TABLE it_extract
FROM vbrk INNER JOIN vbrp ON
vbrk~vbeln = vbrp~vbeln
WHERE vbrk~vbeln IN s_vbeln
AND vbrk~fkart IN s_fkart
AND vbrk~fkdat IN s_fkdat
AND vbrk~vkorg IN s_vkorg
AND vbrk~fksto NE 'X'
AND vbrk~zzflag = 'X'
AND vbrp~werks IN s_werks.
ENDIF.
IF sy-subrc <> 0.
MESSAGE i000 WITH text-002 ' ' ' ' ' '.
ENDIF.
CHECK sy-subrc = 0.
* only need first line item for this report.
SORT it_extract BY vbeln posnr.
DELETE ADJACENT DUPLICATES FROM it_extract COMPARING vbeln.
LOOP AT it_extract.
* Retrieve and select by sales order bill-to on header level
* as well as lookup bill-to customer name/description
SELECT SINGLE kunnr FROM vbpa INTO it_extract-kunnr
WHERE vbeln = it_extract-vbeln
AND posnr = '000000'
AND parvw = 'RE'.
IF it_extract-kunnr IN s_kunnr.
it_extract-kunnr_name1 = zcl_kna1=>get_name1( it_extract-kunnr ).
ELSE.
DELETE it_extract.
CONTINUE.
ENDIF.
* lookup billing type description
SELECT SINGLE vtext FROM tvfkt
INTO it_extract-vtext
WHERE spras = sy-langu
AND fkart = it_extract-fkart.
IF sy-subrc <> 0.
clear it_extract-vtext.
ENDIF.
* lookup plant description
SELECT SINGLE name1 FROM t001w
INTO it_extract-werks_name1
WHERE werks = it_extract-werks.
IF sy-subrc <> 0.
clear it_extract-werks_name1.
ENDIF.
MOVE-CORRESPONDING it_extract TO it_extract2.
APPEND it_extract2.
ENDLOOP.
describe table it_extract2 lines l_count.
ENDFORM. " EXTRACT_DATA
*& Form SET_FIELDCAT
* Create the field catalogue.
FORM set_fieldcat .
*CLEAR W_EVENT.
*W_EVENT-FORM = SLIS_EV_AFTER_OUTPUT.
*W_EVENT-NAME = SLIS_EV_AFTER_LINE_OUTPUT.
*APPEND W_EVENT TO GT_EVENTS.
CLEAR w_field.
CLEAR t_fieldcat. REFRESH t_fieldcat.
w_field-col_pos = 1.
w_field-fieldname = 'ZZFLAG'.
w_field-tabname = 'IT_EXTRACT2'.
w_field-seltext_l = 'Hold Printing'(005).
APPEND w_field TO t_fieldcat.
w_field-col_pos = 2.
w_field-fieldname = 'ZZREASON'.
w_field-tabname = 'IT_EXTRACT2'.
w_field-seltext_l = 'Reason'(036).
APPEND w_field TO t_fieldcat.
w_field-col_pos = 3 .
w_field-fieldname = 'VBELN'.
w_field-tabname = 'IT_EXTRACT2'.
w_field-seltext_l = 'Billing Doc'(028).
w_field-emphasize = 'X'.
w_field-hotspot = 'X'.
APPEND w_field TO t_fieldcat.
CLEAR w_field.
w_field-col_pos = 4 .
w_field-fieldname = 'VTEXT'.
w_field-tabname = 'IT_EXTRACT2'.
w_field-seltext_l = 'Type Description'(030).
APPEND w_field TO t_fieldcat.
w_field-col_pos = 5 .
w_field-fieldname = 'FKDAT'.
w_field-tabname = 'IT_EXTRACT2'.
w_field-seltext_l = 'Billing Date'(031).
APPEND w_field TO t_fieldcat.
w_field-col_pos = 6 .
w_field-fieldname = 'WERKS'.
w_field-tabname = 'IT_EXTRACT2'.
w_field-seltext_l = 'Plant'(012).
APPEND w_field TO t_fieldcat.
w_field-col_pos = 7 .
w_field-fieldname = 'WERKS_NAME1'.
w_field-tabname = 'IT_EXTRACT2'.
w_field-seltext_l = 'Plant Description'(032).
APPEND w_field TO t_fieldcat.
w_field-col_pos = 8.
w_field-fieldname = 'KUNNR'.
w_field-tabname = 'IT_EXTRACT2'.
w_field-seltext_l = 'Bill-to Customer'(033).
APPEND w_field TO t_fieldcat.
w_field-col_pos = 9 .
w_field-fieldname = 'KUNNR_NAME1'.
w_field-tabname = 'IT_EXTRACT2'.
w_field-seltext_l = 'Bill-to Description'(034).
w_field-emphasize = 'X'.
w_field-hotspot = 'X'.
APPEND w_field TO t_fieldcat.
CLEAR w_field.
w_field-col_pos = 10 .
w_field-fieldname = 'NETWR'.
w_field-tabname = 'IT_EXTRACT2'.
w_field-seltext_l = 'Invoice Amount'(035).
APPEND w_field TO t_fieldcat.
w_field-col_pos = 11 .
w_field-fieldname = 'ZZUSER'.
w_field-tabname = 'IT_EXTRACT2'.
w_field-seltext_l = 'Changed By'.
APPEND w_field TO t_fieldcat.
w_field-col_pos = 12 .
w_field-fieldname = 'ZZ_CHANGED_DATE'.
w_field-tabname = 'IT_EXTRACT2'.
w_field-seltext_l = 'Last Changed Date'(006).
APPEND w_field TO t_fieldcat.
w_field-col_pos = 13 .
w_field-fieldname = 'ZZ_CHANGED_TIME'.
w_field-tabname = 'IT_EXTRACT2'.
w_field-seltext_l = 'Last Changed Time'(007).
APPEND w_field TO t_fieldcat.
* W_event-NAME = slis_ev_end_of_list.
* W_event-FORM = 'END_OF_LIST'.
* APPEND W_event TO GT_EVENTS.
* CLEAR W_event .
* w_field-col_pos = 14 .
* w_field-fieldname = 'COUNT'.
* w_field-tabname = 'IT_EXTRACT2'.
* w_field-seltext_l = 'COUNT'.
* APPEND w_field TO t_fieldcat.
ENDFORM. " SET_FIELDCAT
*& Form CALL_ALV
* Call the ALV Grid function.
FORM call_alv .
SORT it_extract BY vbeln.
* repid is necessary since the ALV F.M. does not work properly with
* sy-repid.
repid = sy-repid.
alv_variant-variant = pa_vari.
alv_variant-report = sy-repid.
alv_variant-username = sy-uname.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = repid
i_callback_user_command = 'USER_COMMAND'
is_layout = gs_layout
it_fieldcat = t_fieldcat[]
it_sort = gt_sort[]
i_default = 'X'
i_save = 'A'
is_variant = alv_variant
it_events = gt_events[]
is_print = tp_print
TABLES
t_outtab = it_extract2
EXCEPTIONS
program_error = 1
OTHERS = 2.
write :/ 'TOTAL NO OF ENTRIES', SY-VLINE, 32 L_COUNT.
IF sy-subrc NE 0.
MESSAGE w000 WITH text-004 ' ' ' ' ' '.
ENDIF.
ENDFORM. " CALL_ALV
*& Form alv_eventtab_build
* Pass list of events to be triggered by the ALV function module
FORM alv_eventtab_build USING u_name TYPE slis_alv_event-name
u_form TYPE slis_alv_event-form
alv_lt_events TYPE slis_t_event.
DATA: ls_event TYPE slis_alv_event. " structure for event handling
ls_event-name = u_name.
ls_event-form = u_form.
APPEND ls_event TO alv_lt_events.
ENDFORM. " alv_eventtab_build
* FORM TOP_OF_PAGE *
FORM top_of_page.
*gs_list_top_of_page-type = 'H'.
GS_LIST_TOP_OF_PAGE-INFO = L_COUNT.
APPEND GS_LIST_TOP_OF_PAGE TO GT_LIST_TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
i_logo = 'NEWALTA_LOGO'
it_list_commentary = gt_list_top_of_page.
ENDFORM. " TOP_OF_PAGE
*& Form user_command
* Process the user command.
* -->R_UCOMM User command
* -->RS_SELFIELD Field selected
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
DATA: ltp_vbeln TYPE vbeln. " Sales document number.
CASE r_ucomm.
WHEN '&IC1'.
IF ( rs_selfield-fieldname = 'VBELN'
OR rs_selfield-fieldname = 'BILL_VBELN' )
AND rs_selfield-value IS NOT INITIAL. " Display sales document.
ltp_vbeln = rs_selfield-value.
zcl_sales_doc=>display( ltp_vbeln ).
ENDIF.
ENDCASE.
ENDFORM. "user_command
*& Form alv_v-ariant_f4
* Get the display variant.
* <--CTP_VARI Variant name
FORM alv_variant_f4 CHANGING ctp_vari TYPE slis_vari.
alv_variant-report = sy-repid. " Report ID
alv_variant-username = sy-uname. " User ID
CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
is_variant = alv_variant
i_save = 'A'
IMPORTING
es_variant = alv_variant
EXCEPTIONS
OTHERS = 1.
IF sy-subrc = 0.
ctp_vari = alv_variant-variant.
ENDIF.
ENDFORM. " alv_variant_f4 -
ABAP WD: Count of rows using display_type_hierarchy in ALV
Hi,
I am trying to implement display_type_hierarchy in ALV and my requirement is to change the hierarchy based on user selection.
I am able to get the hierarchy based on user selection. For ex: If there are 3 columns in ALV then user can choose the column in a dropdown box and see the hierarchy based on the chosen column. But I want to get the count of rows inside the hierarchy. I did not find any standard method for this. (Is there one?) Could you please let me know how to do it?
Regards,
Srini.G'day Anett,
Did you manage to get an answer to this issue, we are trying to do the same thing.
Cheers,
Mick. -
'Count all rows' in Disco Plus?
Hi all - I can't find an option to Count All Rows in disco plus. This is something my users use all the time in Desktop - is it included in Plus?
In Desktop, it is under menu item 'Sheet'
Thanks!
ScottHi Scott
Sorry that was removed from Discoverer Plus so you won't find a button for it. Having that there would force Discoverer to have to run the entire query just to give you the total count. Oracle considered this a waste of resource and query effort, which I sort of agree with because I can see what they are getting at, and so removed it.
Best wishes
Michael -
URGENT - Does Select Query Sort based on RowId ?
Does Select Query Sort based on RowId ?
Eg: Select * from Employee;
RowId primkey name
aaaa 1 kiran
aaab 2 kumar
aaac 3 someone
Now when i delete the primkey: 2 row.
I will have:
RowId primkey name
aaaa 1 kiran
aaac 3 someone
Now when i insert a new record:
RowId primkey name
aaaa 1 kiran
aaac 3 someone
[Comment: Here the rowid can either be a new one like 'aaad' or 'aaab' is also reused.]
aaad 4 somename
My requirement is that the 'aaab' should not be reused.
Can any one pls suggest some way.Dear Friend,
Plese gothrougth once following steps... (One by One)
Hope you can understand how Rowid Creating and Updting in you table.
SQL> select rowid,enumber from t;
ROWID ENUMBER
AAAJ4oAABAAAWlyAAA 1
AAAJ4oAABAAAWlyAAB 2
AAAJ4oAABAAAWlyAAC 3
AAAJ4oAABAAAWlyAAD 4
SQL> select rowid,enumber from t where enumber = 2;
1 row deleted.
SQL> insert into t values(9):
1 row created.
SQL> select rowid,enumber from t;
ROWID ENUMBER
AAAJ4oAABAAAWlyAAA 1
AAAJ4oAABAAAWlyAAC 3
AAAJ4oAABAAAWlyAAD 4
AAAJ4oAABAAAWlyAAE 9
SQL> delete from t where enumber = 3;
1 row deleted.
SQL> insert into t values(3);
1 row created.
SQL> select rowid,enumber from t;
ROWID ENUMBER
AAAJ4oAABAAAWlyAAA 1
AAAJ4oAABAAAWlyAAB 3
AAAJ4oAABAAAWlyAAD 4
AAAJ4oAABAAAWlyAAE 9
Regards,
G V Sreenivasulu -
Table Sorting based on Column Selection
Dear All,
I am using an AbstractTableModel. I would like to implement the sorting based on Column selection. Could anyone help me in this please.
Thanks in advance,
Regards
Irfaancheck this
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumnModel;
import java.awt.Component;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Hashtable;
public class TableSorter extends JPanel
private boolean DEBUG = false;
private Object[] columnNames = { "First Name", "Last Name", "Sport", "# of Years",
"Vegetarian"};
private Object[][] data = { { "Mary", "Campione", "Snowboarding", 1, 2 },
{ "Alison", "Huml", "Rowing", 3, 4 }, { "Kathy", "Walrath", "Knitting", 5, 9 },
{ "Sharon", "Zakhour", "Speed reading", 6, 10 }, { "Philip", "Milne", "Pool", 7, 11 },
{ "Isaac", "Rabinovitch", "Nitpicking", 8, 12 }, };
private SortFilterModel m_modSortFilterModel;
private TableColumnModel m_modColumnModel;
private TableHeaderRenderer m_btnSorterRenderer;
protected boolean m_bAbCOC = true;
JTable table = new JTable();
public TableSorter()
super(new GridLayout(1, 0));
m_modSortFilterModel = new SortFilterModel();
m_modSortFilterModel.addMouseListener(table);
table.setModel(m_modSortFilterModel);
m_btnSorterRenderer = new TableHeaderRenderer();
m_modColumnModel = table.getColumnModel();
for (int i = 0; i < columnNames.length; i++)
m_modColumnModel.getColumn(i).setHeaderRenderer(m_btnSorterRenderer);
JScrollPane scrollPane = new JScrollPane(table);
add(scrollPane);
private class SortFilterModel extends AbstractTableModel
int[] indexes;
ATSTableSorter sorter;
public String[] tableHeadersArray;
boolean isAscent = true;
public void addMouseListener(final JTable table)
table.getTableHeader().addMouseListener(new MouseAdapter()
public void mouseClicked(MouseEvent event)
int tableColumn = table.columnAtPoint(event.getPoint());
m_btnSorterRenderer.setPressedColumn(tableColumn);
m_btnSorterRenderer.setSelectedColumn(tableColumn);
if (TableHeaderRenderer.DOWN == m_btnSorterRenderer.getState(tableColumn))
isAscent = true;
else
isAscent = false;
// translate to table model index and sort
int modelColumn = table.convertColumnIndexToModel(tableColumn);
sortByColumn(modelColumn, isAscent);
public Object getValueAt(int row, int col)
int rowIndex = row;
if (indexes != null)
rowIndex = indexes[row];
return data[rowIndex][col];
public void setValueAt(Object value, int row, int col)
int rowIndex = row;
if (indexes != null)
rowIndex = indexes[row];
super.setValueAt(value, rowIndex, col);
public void sortByColumn(int column, boolean isAscent)
if (sorter == null)
sorter = new ATSTableSorter(this);
sorter.sort(column, isAscent);
fireTableDataChanged();
public int[] getIndexes()
int n = getRowCount();
if (indexes != null)
if (indexes.length == n)
return indexes;
indexes = new int[n];
for (int i = 0; i < n; i++)
indexes[i] = i;
return indexes;
public int getRowCount()
return data.length;
public String getColumnName(int c)
return columnNames[c].toString();
public int getColumnCount()
return columnNames.length;
public Class getColumnClass(int col)
switch (col)
case 0:
return String.class;
case 1:
return String.class;
case 2:
return String.class;
case 3:
return Integer.class;
case 4:
return Integer.class;
default:
return Object.class;
class ATSTableSorter
SortFilterModel model;
public ATSTableSorter(SortFilterModel model)
this.model = model;
public void sort(int column, boolean isAscent)
int n = model.getRowCount();
int[] indexes = model.getIndexes();
for (int i = 0; i < n - 1; i++)
int k = i;
for (int j = i + 1; j < n; j++)
if (isAscent)
if (compare(column, j, k) < 0)
k = j;
else
if (compare(column, j, k) > 0)
k = j;
int tmp = indexes;
indexes[i] = indexes[k];
indexes[k] = tmp;
public int compare(int column, int row1, int row2)
Object o1 = model.getValueAt(row1, column);
Object o2 = model.getValueAt(row2, column);
if (o1 == null && o2 == null)
return 0;
else if (o1 == null)
return -1;
else if (o2 == null)
return 1;
else
Class type = model.getColumnClass(column);
if (type.getSuperclass() == Number.class)
return compare((Number) o1, (Number) o2);
else if (type == String.class)
return ((String) o1).compareTo((String) o2);
else
return ((String) o1).compareTo((String) o2);
public int compare(Number o1, Number o2)
double n1 = o1.doubleValue();
double n2 = o2.doubleValue();
if (n1 < n2)
return -1;
else if (n1 > n2)
return 1;
else
return 0;
class TableHeaderRenderer extends JButton implements TableCellRenderer
public static final int NONE = 0;
public static final int DOWN = 1;
public static final int UP = 2;
int pushedColumn;
Hashtable state;
public TableHeaderRenderer()
pushedColumn = -1;
state = new Hashtable();
setMargin(new Insets(0, 0, 0, 0));
setHorizontalTextPosition(LEFT);
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus,
int row, int column)
setText((value == null) ? "" : value.toString());
setBorder(UIManager.getBorder("TableHeader.cellBorder"));
boolean isPressed = (column == pushedColumn);
getModel().setPressed(isPressed);
getModel().setArmed(isPressed);
return this;
public void setPressedColumn(int col)
pushedColumn = col;
public void setSelectedColumn(int col)
if (col < 0)
return;
Integer value = null;
Object obj = state.get(new Integer(col));
if (obj == null)
value = new Integer(DOWN);
else
if (((Integer) obj).intValue() == DOWN)
value = new Integer(UP);
else
value = new Integer(DOWN);
state.clear();
state.put(new Integer(col), value);
public int getState(int col)
int retValue;
Object obj = state.get(new Integer(col));
if (obj == null)
retValue = NONE;
else
if (((Integer) obj).intValue() == DOWN)
retValue = DOWN;
else
retValue = UP;
return retValue;
private static void createAndShowGUI()
JFrame frame = new JFrame("TableDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
TableSorter newContentPane = new TableSorter();
newContentPane.setOpaque(true); // content panes must be opaque
frame.setContentPane(newContentPane);
frame.pack();
frame.setVisible(true);
public static void main(String[] args)
javax.swing.SwingUtilities.invokeLater(new Runnable()
public void run()
createAndShowGUI(); -
How to filter a report based on count?
Here is my scenario: We would like to report activities on a server if there are multiple date in a month. Here is an example:
Server Date Activity
Server1 7/1/09 Hardware maintenance
Server2 7/1/09 Hardware maintenance
Server2 7/14/09 Software patching
Server2 7/14/09 Server reboot
Server3 7/5/09 Hardware maintenance
Server3 7/5/09 Server reboot
The report will show the following
Server2 7/1/09 Hardware maintenance
Server2 7/14/09 Software patching
Server2 7/14/09 Server reboot
Server1 and Server3 will not show up since there is only one date in July (even though there are two activities for Server3).
I thought of using a report as a filter to a second report. In the first report, find a way to determine which server to report on. But how would I finter the 1st report based on count as the logic stated above?Hi Max
Our requirement is to see all the activities for a server in a month ONLY IF there are activities on DIFFERENT dates. So using my example, server2 has activties on 7/1 and 7/14. Then we want to see all the activities for server2 in that month. Server3 has two activities but both activities are on the same date. So we don't want to see server3.
Counting by server will not work because that will include server3 in my example.
What I really want is to be able to count unique occurrences of dates per server in a month. And if this count is > 1, then this server will be in the report.
I used a pivot table to count the unique occurrences of dates by server by month. So using my example, I have this result:
Server1-July: 1
Server2-July: 2
Server3-July 1
What I really want (conceptually) is to be able to filter this pivot table by the matrix column which is the count. I just couldn't figure out how to do that :). Then I thought I could use this report (with pivot table result) as a filter into another report.
Hope you have some idea....:)
Thanks -
Count of rows from different tables.
Hi Friends,
I have 4 tables with a common column name "ID". I would like to get the count of rows from all the four tables which has the same ID.
Ex
select count(a.id) from table1 a,table2 b,table3 c,table4 d where a.id=b.id=c.id=d.id=5;
please suggest me some solutionmay be thsi?
select count(a.id) from table1 a,table2 b,table3 c,table4 d
where a.id=b.id and a.id=c.id and a.id=d.id and a.id=5; -
Hi There,
I am trying to create a measure in cube browser which will return count of rows of a table. If there are some rows, it returns correct result but in other case if table is empty, it returns nothing.
I want to return 0 in later case.
Please advise.You could create a Measure with code. Something like this, it is made in AdventureWorks2014.
CREATE MEMBER CurrentCube.Measures.[Count Rows Dimension] AS
CoalesceEmpty(COUNT([Customer].[Customer].[Customer]),0),
Associated_Measure_Group = 'Measure Group you want it associated to'; -
Hi ,
I want to find count of rows of a particular data set in a table expression. How to do that? Can you please help me out.
Thanks
susheel
sushHi Dimant,
I used countrows. If the dataset set contains 12 rows I am getting the o/p as shown below. I just need one row. Can please help me out.
Thanks
sush -
Count the rows in a list-component
Hi,
How can I count the rows with a value in a list component?
I thought it would be RowCount but as I figured out that shows the number of shown rows, not the number of rows with a value.Hi,
Try list.dataProvider.length -
Count of rows of a table in header
Hi Experts,
I am stuck in a tricky scenario.
I need to get the count of rows of a table in a webi report in the header of the report.
And the count should change dynamically according to the filtering done on the table.
For eg.
If I have 10 countries in a table, so table has 10 rows.
Now the count on header should show 10.
Now if we filter the column to 5 countries, the count on the header should change to 5.
Any Idea's.
Regards,
GauravNops
It doesn't work.
Let me reframe my issue again:
I dragged country object on my report.
UK
US
JAPAN
CANADA
Now lets say in the report title, I write the formula as =Count(country)
It will give me 4.
Now I clicked on the column country and applied filter i.e. country = US ; UK
Now the block shows
UK
US
In the header the cell still shows 4, which I want to see as 2.
Any ideas....?
Thanks
Gaurav
Maybe you are looking for
-
How can i add one month to a date variable ?
Unlike the week which always 7 days, month may change from 28 to 31, so how can i add one month to a date variable ? Thanks in advance.
-
How to view execution history for any date in oracle SQL developer tool ?
hi, i want to view some executed queries(2 months before) in oracle SQL Developer. if i press F8 it shows execution history for only last 30 days. is there any option(query) or something to view execution history for specific date ? i want to see som
-
Business Content 0PUR_C01 missing invoice data for consignment
Hi Experts, we have activated content datasource 2LIS_02_ITM and 2LIS_06_SCL in source system and content in BW-system for loading data to Info cube 0PUR_C01. WE did an initial upload of data for both data sources with no problems, except consignment
-
Using weblogic 5.1.0 I create an object and store it in the httpsession when a client accesses a servlet. When a second client logs in, a similar object is created for him and put in the session. When the first
-
Overlay two images in the same container
Hi, I don't know if it's possible, but in my webdynpro application I have a transparent container with an image, amont other stuff, inside. I've created the image as a cl_wd_link_to_action object, because when the user clicks over it, an action is tr