Query for follwing count function
Table T1:
COL 1 COL 2
1 2
3 10
89 4
5 -
- 6
Quest:
Select COL1,count(COL1) from Table t1 group by cOL1;Ans??? Pl
Edited by: 799660 on Oct 3, 2010 5:36 AM
Quit polluting this forum, please.
You're not providing any details reqarding your requirement, database version and so on...
Read: http://tkyte.blogspot.com/2005/06/how-to-ask-questions.html
And use CREATE TABLE + INSERT INTO statements, formatted by using the {noformat}{noformat}tag when you want to post an example.
For example, if you post:
{noformat} select *
from emp;
{noformat}
it will appear as: select *
from emp;
on this forum.
Tags are explained in the FAQ, so read that too: http://forums.oracle.com/forums/help.jspa
Similar Messages
-
Create dynamic report or query for piece count
Hi abaper's
This is a very straight forward requirement. so please give me code
First you have to get the corresponding plant from table T320 for the given warehouse numbers in the selection screen.
1. Get the sum of order qty of sales orders from the sales order tables for the given warehouse(Plant), distribution channel and the give date range.
2. Get the confirmed transfer orders qty from the TO master table where TO confirmation date is in the given date range and WH number.
3. Get the total PGIed qty from the delivery master table where PGI'ed date in the given date range, shipping point is in the corresponding plant of the WH and for the given distribution channel.
As you are going to use the major tables please try to write the select commands effectively to avoid further performance issues.How to improve the performance fo this code.....this very urgent.
& Issue Number : 22199 &
& Programmer : Anjaneyulu.Pabba &
& Transport Number : D01K962471 &
& Date of Creation : 19/03/2008 &
& Description : Dynamic report or query for piece count &
& Requested By : Parvati.Polisetty &
REPORT ZR_SD_PIECE_COUNT_ALV no standard page heading
line-size 255
line-count 65.
TABLES DECLARATION
*TABLES: T320, "Assignment IM Storage Location to WM Warehouse Number
VBAK, "Sales Document: Header Data
VBAP, "Sales Document: Item Data
TVKOV, "Org. Unit: Distribution Channels per Sales Organization
LTAK, "WM transfer order header
LTAP, "Transfer order item
LIKP, "SD Document: Delivery Header Data
LIPS. "SD document: Delivery: Item data
TYPE-POOLS DECLARATION
TYPE-POOLS: SLIS .
Internal Table Declaration
DATA : BEGIN OF TY_T320,
WERKS TYPE WERKS_D,
LGNUM TYPE LGNUM,
END OF TY_T320.
DATA : BEGIN OF TY_VBAK,
VBELN TYPE VBELN_VA,
VTWEG TYPE VTWEG,
WERKS TYPE WERKS_D,
KWMENG TYPE KWMENG,
VSTEL TYPE VSTEL,
END OF TY_VBAK.
DATA : BEGIN OF TY_LTAK,
LGNUM TYPE LGNUM,
TANUM TYPE TANUM,
VISTA TYPE LTAP_VISTA,
END OF TY_LTAK.
DATA : BEGIN OF TY_LIKP,
VBELN TYPE VBELN_VL,
WERKS TYPE WERKS_D,
LFIMG TYPE LFIMG,
END OF TY_LIKP.
DATA : BEGIN OF TY_ITAB ,
LGNUM TYPE LGNUM, "Warehouse Number / Warehouse Complex
WERKS TYPE WERKS_D, "Plant
VBELN TYPE VBELN_VA, "Sales Document
VTWEG TYPE VTWEG, "Distribution Channel
KWMENG TYPE KWMENG, "Cumulative order quantity in sales units
TANUM TYPE TANUM , "Transfer Order Number
VISTA TYPE LTAP_VISTA, "Source actual quantity in alternative
unit of measure
LFIMG TYPE LFIMG, "Actual quantity delivered (in sales units)
END OF TY_ITAB .
DATA: T_T320 LIKE STANDARD TABLE OF TY_T320 INITIAL SIZE 0 WITH HEADER
LINE,
T_VBAK LIKE STANDARD TABLE OF TY_VBAK INITIAL SIZE 0 .
DATA: T_LTAK LIKE STANDARD TABLE OF TY_LTAK INITIAL SIZE 0 WITH HEADER
LINE.
DATA :T_LIKP LIKE STANDARD TABLE OF TY_LIKP INITIAL SIZE 0 WITH HEADER
LINE.
DATA:T_ITAB LIKE STANDARD TABLE OF TY_ITAB INITIAL SIZE 0 WITH HEADER
LINE .
*& Fieldcatalog Declaration
DATA : T_FCAT TYPE SLIS_T_FIELDCAT_ALV,
W_FCAT TYPE SLIS_FIELDCAT_ALV.
DATA : W_LAYOUT TYPE SLIS_LAYOUT_ALV.
********Global Data Declaration***
DATA :G_REPID LIKE SY-REPID,
G_EXIT(1) TYPE C,
GX_VARIANT LIKE DISVARIANT,
X_SAVE, "for Parameter I_SAVE
GS_VARIANT TYPE DISVARIANT. "for parameter IS_VARIANT
data: g_lgnum type t320-lgnum,
g_vtweg type vbak-vtweg,
g_erdat type vbak-erdat.
*& Selection-Screen
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS : S_LGNUM FOR g_lgnum, "Warehouse Number
S_VTWEG FOR g_vtweg, "Distribution Channel
S_ERDAT FOR g_erdat ."Date on which the record was
**********"created
SELECTION-SCREEN END OF BLOCK B1 .
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.
PARAMETER: P_VARI LIKE DISVARIANT-VARIANT. "Layout
SELECTION-SCREEN END OF BLOCK B2.
*& INITIALIZATION EVENT
INITIALIZATION.
CLEAR GS_VARIANT.
'gs_variant' must at least contain the report-id to allow
saving a variant.
G_REPID = SY-REPID.
§ 2.At least field REPORT of this structure has to be filled!
GS_VARIANT-REPORT = G_REPID.
§ 3.Determine saving options.
X_SAVE = 'A'. "The user may save all types of variants
*******Validating selection-screen values**********************
getting F4 value for display variant field
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_VARI.
PERFORM F4_FOR_VARIANT.
****validation of F4 value of display variant
AT SELECTION-SCREEN.
PERFORM PAI_OF_SELECTION_SCREEN.
*& Start-Of-Selection
START-OF-SELECTION.
*****Subroutine to select Plant from T320
PERFORM FIND_PLANT .
*****Subroutine to select Order Quantity from VBAP
PERFORM ORDER_QUANTITY .
*****Subroutine to select Transfer Order Quantity from LTAK and LTAP
PERFORM TRANSFER_ORDER_QUANTITY.
*****Subroutine to select TDelivery Quantity from LIKP and LIPS
PERFORM DELIVERY_QUANTITY.
*& End-Of-Selection
END-OF-SELECTION.
*****Subroutine for Fieldcatalog
PERFORM FIELDCATALOG .
*****Subroutine for Final Output
PERFORM DISPLAY_OUTPUT .
*& Subroutine Implementaion
*& Form FIND_PLANT
text
--> p1 text
<-- p2 text
FORM FIND_PLANT .
SELECT WERKS
LGNUM
FROM T320
INTO TABLE T_T320
WHERE LGNUM IN S_LGNUM.
ENDFORM. " FIND_PLANT
*& Form order_quantity
text
--> p1 text
<-- p2 text
FORM ORDER_QUANTITY .
SELECT VK~VBELN
VK~VTWEG
VP~WERKS
VP~KWMENG
VP~VSTEL
INTO TABLE T_VBAK FROM VBAK AS VK
INNER JOIN VBAP AS VP
ON VKVBELN = VPVBELN
FOR ALL ENTRIES IN T_T320
WHERE VK~VTWEG IN S_VTWEG
AND VK~ERDAT IN S_ERDAT
AND VP~WERKS = T_T320-WERKS.
ENDFORM. " order_quantity
*& Form Transfer_order_quantity
text
--> p1 text
<-- p2 text
FORM TRANSFER_ORDER_QUANTITY .
SELECT LK~LGNUM
LK~TANUM
LP~VISTA
INTO TABLE T_LTAK FROM LTAK AS LK
INNER JOIN LTAP AS LP
ON LKLGNUM = LPLGNUM
WHERE LK~KQUIT = 'X'
AND LK~BDATU IN S_ERDAT
AND LK~LGNUM IN S_LGNUM.
ENDFORM. " Transfer_order_quantity
*& Form Delivery_QUANTITY
text
--> p1 text
<-- p2 text
FORM DELIVERY_QUANTITY .
SELECT VBELN WERKS LFIMG FROM LIPS
INTO TABLE T_LIKP
FOR ALL ENTRIES IN T_T320
WHERE WERKS = T_T320-WERKS
AND ERDAT IN S_ERDAT
AND VTWEG IN S_VTWEG.
ENDFORM. " Delivery_QUANTITY
*& Form fieldcatalog
text
--> p1 text
<-- p2 text
FORM FIELDCATALOG .
W_FCAT-COL_POS = '1' .
W_FCAT-FIELDNAME = 'LGNUM' .
W_FCAT-REF_TABNAME = 'T320'.
W_FCAT-REF_FIELDNAME = 'LGNUM' .
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-COL_POS = '2' .
W_FCAT-FIELDNAME = 'VTWEG' .
W_FCAT-REF_TABNAME = 'VBAK'.
W_FCAT-REF_FIELDNAME = 'VTWEG' .
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-COL_POS = '3' .
W_FCAT-FIELDNAME = 'KWMENG' .
W_FCAT-REF_TABNAME = 'VBAP'.
W_FCAT-REF_FIELDNAME = 'KWMENG' .
*w_fcat-seltext_m = '# of Orders'.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-COL_POS = '4' .
W_FCAT-FIELDNAME = 'VISTA' .
W_FCAT-REF_TABNAME = 'LTAP'.
W_FCAT-REF_FIELDNAME = 'VISTA' .
*w_fcat-seltext_m = '# of Pcs Picked'.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-COL_POS = '5' .
W_FCAT-FIELDNAME = 'LFIMG' .
W_FCAT-REF_TABNAME = 'LIPS'.
W_FCAT-REF_FIELDNAME = 'LFIMG' .
*w_fcat-seltext_m = '# of Pcs Shipped'.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-COL_POS = '6' .
W_FCAT-FIELDNAME = 'TANUM' .
W_FCAT-REF_TABNAME = 'LTAK'.
W_FCAT-REF_FIELDNAME = 'TANUM' .
**w_fcat-seltext_m = '# of Pcs Shipped'.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-COL_POS = '7' .
W_FCAT-FIELDNAME = 'WERKS' .
W_FCAT-REF_TABNAME = 'T320'.
W_FCAT-REF_FIELDNAME = 'WERKS' .
**w_fcat-seltext_m = '# of Pcs Shipped'.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
ENDFORM. " fieldcatalog
*& Form display_output
text
--> p1 text
<-- p2 text
FORM DISPLAY_OUTPUT .
LOOP AT T_T320 INTO TY_T320.
TY_ITAB-WERKS = TY_T320-WERKS.
TY_ITAB-LGNUM = TY_T320-LGNUM.
READ TABLE T_VBAK INTO TY_VBAK WITH KEY WERKS = TY_T320-WERKS.
IF SY-SUBRC = 0.
TY_ITAB-VBELN = TY_VBAK-VBELN.
TY_ITAB-VTWEG = TY_VBAK-VTWEG.
TY_ITAB-KWMENG = TY_VBAK-KWMENG + ty_itab-kwmeng.
ENDIF.
READ TABLE T_LTAK INTO TY_LTAK WITH KEY LGNUM = TY_T320-LGNUM.
IF SY-SUBRC = 0.
TY_ITAB-TANUM = TY_LTAK-TANUM.
TY_ITAB-VISTA = TY_LTAK-VISTA + ty_itab-vista.
ENDIF.
READ TABLE T_LIKP INTO TY_LIKP WITH KEY WERKS = TY_T320-WERKS.
IF SY-SUBRC = 0.
TY_ITAB-LFIMG = TY_LIKP-LFIMG + ty_itab-lfimg.
ENDIF.
APPEND TY_ITAB TO T_ITAB.
ENDLOOP.
Function Module for Displaying Final Output ********
W_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-CPROG
IS_LAYOUT = W_LAYOUT
IT_FIELDCAT = T_FCAT[]
TABLES
T_OUTTAB = T_ITAB.
ENDFORM. " display_output
*& Form f4_for_variant
text
--> p1 text
<-- p2 text
FORM F4_FOR_VARIANT .
CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
IS_VARIANT = GS_VARIANT
I_SAVE = X_SAVE
IMPORTING
E_EXIT = G_EXIT
ES_VARIANT = GX_VARIANT
EXCEPTIONS
NOT_FOUND = 2.
IF SY-SUBRC = 2.
MESSAGE ID SY-MSGID TYPE 'S' NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
IF G_EXIT = SPACE.
P_VARI = GX_VARIANT-VARIANT.
ENDIF.
ENDIF.
ENDFORM. " f4_for_variant
*& Form pai_of_selection_screen
text
--> p1 text
<-- p2 text
FORM PAI_OF_SELECTION_SCREEN .
IF NOT P_VARI IS INITIAL.
MOVE GS_VARIANT TO GX_VARIANT.
MOVE P_VARI TO GX_VARIANT-VARIANT.
CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
EXPORTING
I_SAVE = X_SAVE
CHANGING
CS_VARIANT = GX_VARIANT.
GS_VARIANT = GX_VARIANT.
ELSE.
PERFORM VARIANT_INIT.
ENDIF.
ENDFORM. " pai_of_selection_screen
*& Form variant_init
text
--> p1 text
<-- p2 text
FORM VARIANT_INIT .
CLEAR GS_VARIANT.
GS_VARIANT-REPORT = G_REPID.
ENDFORM. " variant_init -
Query for getting all function and procedure inside the packages
hi All
Please provide me Query for getting all function and procedure inside the packages
thanksAs Todd said, you can use user_arguments data dictionary or you can join user_objects and user_procedures like below to get the name of the packaged function and procedure names.
If you are looking for the packaged procedures and functions source then use user_source data dictionary
select a.object_name,a.procedure_name from user_procedures a,
user_objects b
where a.object_name is not null
and a.procedure_name is not null
and b.object_type='PACKAGE'
and a.object_name=b.object_name -
How to use the result of a sql query for a max () function
Hi
I wrote a query on which i wrote
"select max(id) from users "
how can i use the returned value.
if i made the var name ="userid"
can it be userid.rows[0] or what.
thnx for any helpHi!
The result of this query will be the max ID of users' IDs.
Let say we have:
String sql="select max(users.id) from users";
Statement st = ctx.conn.createStatement();
ResultSet rs = st.executeQuery(sql);
rs.next();
So you can get the max Id in the following way:
int maxId=rs.getInt("id");
Regards,
Rossi -
Query for using "analytical functions" in DWH...
Dear team,
I would like to know if following task can be done using analytical functions...
If it can be done using other ways, please do share the ideas...
I have table as shown below..
Create Table t As
Select *
From
Select 12345 PRODUCT, 'W1' WEEK, 10000 SOH, 0 DEMAND, 0 SUPPLY, 0 EOH From dual Union All
Select 12345, 'W2', 0, 100, 50, 0 From dual Union All
Select 12345, 'W3', 0, 100, 50, 0 From dual Union All
Select 12345, 'W4', 0, 100, 50, 0 From dual
PRODUCT WEEK SOH DEMAND SUPPLY EOH
12345 W1 10,000 0 0 10000
12345 W2 0 100 50 0
12345 W3 0 100 50 0
12345 W4 0 100 50 0
Now i want to calcuate EOH (ending on hand) quantity for W1...
This EOH for W1 becomes SOH (Starting on hand) for W2...and so on...till end of weeks
The formula is :- EOH = SOH - (DEMAND + SUPPLY)
The output should be as follows...
PRODUCT WEEK SOH DEMAND SUPPLY EOH
12345 W1 10,000 10000
12345 W2 10,000 100 50 9950
12345 W3 9,950 100 50 9900
12345 W4 9,000 100 50 8950
Kindly share your ideas...Nicloei W wrote:
Means SOH_AFTER_SUPPLY for W1, should be displayed under SOH FOR W2...i.e. SOH for W4 should be SOH_AFTER_SUPPLY for W3, right?
If yes, why are you expecting it to be 9000 for W4??
So in output should be...
PRODUCT WE SOH DEMAND SUPPLY EOH SOH_AFTER_SUPPLY
12345 W1 10000 0 0 0 10000
12345 W2 10000 100 50 0 9950
12345 W3 9950 100 50 0 *9900*
12345 W4 *9000* 100 50 0 9850
per logic you explained, shouldn't it be *9900* instead???
you could customize Martin Preiss's logic for your requirement :
SQL> with
2 data
3 As
4 (
5 Select 12345 PRODUCT, 'W1' WEEK, 10000 SOH, 0 DEMAND, 0 SUPPLY, 0 EOH Fom dual Union All
6 Select 12345, 'W2', 0, 100, 50, 0 From dal Union All
7 Select 12345, 'W3', 0, 100, 50, 0 From dal Union All
8 Select 12345, 'W4', 0, 100, 50, 0 From dual
9 )
10 Select Product
11 ,Week
12 , Sum(Soh) Over(Partition By Product Order By Week)- Sum(Supply) Over(Parttion By Product Order By Week)+Supply Soh
13 ,Demand
14 ,Supply
15 , Sum(Soh) Over(Partition By Product Order By Week)- Sum(Supply) Over(Partition By Product Order By Week) eoh
16 from data;
PRODUCT WE SOH DEMAND SUPPLY EOH
12345 W1 10000 0 0 10000
12345 W2 10000 100 50 9950
12345 W3 9950 100 50 9900
12345 W4 9900 100 50 9850 Vivek L -
There is table er_user_groups.ER_USER_GROUPS has username and group_id as fields.
This table contains data about all the groups which user belongs to.
If user is in each of group 29,30,31,32 then access level is basic.Please help me with Sql for this.
User might be part of more group ids but these is minimum crietiraHi,
That sounds like a job for the COUNT function. Count how many of those groups each user is in, and pick the opnes where the count is 4.
Since I don't have a copy of your table, I'll use the scott.emp table (which almost everybody has) to illustrate.
Say we want to find which jobs are in each of the depatments 10, 20 and 30:
SELECT job
FROM scott.emp
WHERE deptno IN (10, 20, 30)
GROUP BY job
HAVING COUNT (DISTINCT deptno) = 3
Output:
JOB
CLERK
MANAGER
It doesn't matter if the same job appears in other departments or not; only rows with the given deptnos (10, 20 and 30) are considered.
As Greg said, see the forum FAQ: https://forums.oracle.com/message/9362002 -
Count() function throws error in EQL query for metric
Hi
I am trying to use count function in EQL query for Metric Bar to show the number of occurrences of a record.
When the record type doesn't exist i expect the function to return count as 0. Instead the function throws a runtime exception and the whole Metric Bar portlet fails, with error No Results Available. Even though other components in the metric bar have valid results.
2013-02-21 13:03:51,216 WARN [MetricsBarQueryProcessor] The EQL query does not return any results.
2013-02-21 13:03:51,216 ERROR [MetricsBarQueryProcessor] The EQL query does not return any results.
2013-02-21 13:03:51,216 WARN [MetricsBarResultsProcessor] No statement results to process.
The EQL query i am using is
RETURN NUMBER_OCCURS AS SELECT COUNT(EMP_ID) AS NUMBER_OCCURS where EMP_NAME IS NOT NULL group;
I tried using COALESCE but that doesn't help.
Can some one please suggest a workaround to this?Srikanth,
Two statements are used here because the original question was pertaining to the null set (where there are employees in the nav state but no employees that fit the special analytics criteria in the navigation state). The question/answer has nothing to do with what is in the COUNT parentheses clause as Counting a null set will always give you NULL, not 0, no matter what you put in there.
What we're really doing, in the second part of the query, is writing a query over a set of data that is not the null set (i.e. the current navigation state). This allows the 0 value to come through in the case where the first analytics statement is evaluated over a null set of records. If there were truly no records in the navigation state, this too would return a null set and not zero.
Hope that makes sense, feel free to respond (either on here or offline) if it's unclear.
Regards,
Patrick Rafferty
http://branchbird.com -
Function returning SQL query for mutiple series in a chart
Hi,
I would like to know if there is a way to specify a single PL/SQL function returning the queries for multiple series in a 2D Line Flash Chart. I have multiple series in my chart that has different values in the where clause. I can write a PL/SQL function that can return all these queries in one shot. Is there anyway that I can specify this function as returning the queries for all the series in the chart?
As an example, assume that I am using the following three queries for the series in my chart:
select deptno, count(*) from emp where deptno = 10 group by deptno
select deptno, count(*) from emp where deptno = 20 group by deptno
select deptno, count(*) from emp where deptno = 30 group by deptno
I can't write a PL/SQL function that returns a query in the multiple series syntax (SELECT link, label, series_1_value [, series_2_value [, ...]]FROM ...) as I am using an aggregate function and my where clause is different for each series.
Thanks,
RupeshHi Roel,
Thanks for your reply. I am already using an analytical function (RATIO_TO_REPORT(COUNT(*)) OVER () ) in my actual report. My problem is that the query for one series differs from the other only in one where clause. I will be able to dynamically able to generate all the queries for all the series in one pl/sql function. But the chart definition screen does not allow us to define a single function that returns queries for the all the series - possibly seperated by some seperator like S1: select.... S2:select and so on.
Regards,
Rupesh -
Hi All.
I was trying to write a query for below result set but can not figure out if i can achieve below result set through T-SQL.
Emplid FunctionId Count
1 2
1 3 1
1 4 2
1 4
1 5 3
1 6 4
1 3
2 3
2 3
2 1 1
2 2 2
Description
When an Employee is changing from job/function, am struggling to get incremental number / count for that employ based on no. of funtionid changed.
I need a count only when an employee is going to do something else (another function).
The example above is showing how the count output should be.
am not sure it i need to use any analytical function, any help would be appreciated.
and many thanks in advance for reading my questionSomething like
SQL> ed
Wrote file afiedt.buf
1 with x as (
2 select 1 empid, 2 functionid, sysdate dt from dual union all
3 select 1, 3, sysdate+1 from dual union all
4 select 1, 4, sysdate+2 from dual union all
5 select 1, 4, sysdate+3 from dual union all
6 select 2, 3, sysdate+4 from dual union all
7 select 2, 3, sysdate+5 from dual union all
8 select 2, 1, sysdate+6 from dual
9 )
10 select empid,
11 functionid,
12 sum(case when functionid = prior_functionid
13 then 0
14 else 1
15 end) over (partition by empid
16 order by dt)-1 cnt
17 from (
18 select empid,
19 functionid,
20 lag(functionid) over (partition by empid
21 order by dt) prior_functionid,
22 dt
23 from x
24* )
SQL> /
EMPID FUNCTIONID CNT
1 2 0
1 3 1
1 4 2
1 4 2
2 3 0
2 3 0
2 1 1
7 rows selected.appears to work
Justin -
Query quiz find a query for sine function distribution
Let me tell you something about distribution function.
Here, i use the term, 'distribution function' differently from what we use in general mathematics.
See the following query which generates self-counting sequence.
SELECT TRUNC (1 / 2 + SQRT (2 * LEVEL)) level#
FROM DUAL
CONNECT BY LEVEL <= 1000LEVEL#
1
2
2
3
3
3
4
4
4
4
5
5
5
5
5
and, if we add some group by and counting to the above query...
SELECT level#
, LPAD ('*', COUNT (*), '*')
FROM (SELECT TRUNC (1 / 2 + SQRT (2 * LEVEL)) level#
FROM DUAL
CONNECT BY LEVEL <= 1000)
GROUP BY level#we can see a graph like below
LEVEL# LPAD('*',COUNT(*),'*')
1 *
2 **
3 ***
4 ****
5 *****
6 ******
7 *******
8 ********
9 *********
10 **********
11 ***********
12 ************
13 *************
14 **************
15 ***************
16 ****************
17 *****************
18 ******************
19 *******************
20 ********************
...As we all know, this is like a function f(x) = x.
i use the term, 'distribution function' as this meaning!
Distribution of numbers of data values.
Now, my question is this.
Find a query that generates distribution function f(x) = sin(x)
(Here, any amplitude and any period of sine function is allowed except zero.
And only the form of sine function is important.
No subquery factoring or user-defined function or procedure is allowed.
Use simple select statement only.)
And now, have a good challenge!
SELECT level#
, LPAD ('*', COUNT (*), '*')
FROM (
-------- some query -------------------
GROUP BY level#
LEVEL# LPAD('*',COUNT(*),'*')
0 *
1 **
2 *******
3 *************
4 *****************
5 **********************
6 **************************
7 ******************************
8 **********************************
9 **************************************
10 ****************************************
11 ********************************************
12 *********************************************
13 ************************************************
14 *************************************************
15 *************************************************
16 **************************************************
17 **************************************************
18 *************************************************
19 ************************************************
20 ***********************************************
21 ********************************************
22 ******************************************
23 ***************************************
24 ***********************************
25 ********************************
26 ****************************
27 ************************
28 *******************
29 **************
30 *********
31 *****Query Your Dream & Future at
http://www.soqool.comIt's cheating but, hey I wanted to draw pretty pictures too... :o))
SQL> SELECT rn as degrees, decode(sign(val),-1,lpad(' ', scale-abs(val), ' ')
2 ||lpad('*',abs(val),'*'), lpad(' ', scale, ' ')||lpad('*',val,'*')) as graph
3 from
4 (select rownum-1 rn, (sin(((rownum-1)/180)*acos(-1))) * x.scale as val, x.scale
5 from dual, (select 50 as scale from dual) x
6 connect by rownum <= 360);
DEGREES GRAPH
0
1
2 *
3 **
4 ***
5 ****
6 *****
7 ******
8 ******
9 *******
10 ********
11 *********
12 **********
13 ***********
14 ************
15 ************
16 *************
17 **************
18 ***************
19 ****************
20 *****************
21 *****************
22 ******************
23 *******************
24 ********************
25 *********************
26 *********************
27 **********************
28 ***********************
29 ************************
30 *************************
31 *************************
32 **************************
33 ***************************
34 ***************************
35 ****************************
36 *****************************
37 ******************************
38 ******************************
39 *******************************
40 ********************************
41 ********************************
42 *********************************
43 **********************************
44 **********************************
45 ***********************************
46 ***********************************
47 ************************************
48 *************************************
49 *************************************
50 **************************************
51 **************************************
52 ***************************************
53 ***************************************
54 ****************************************
55 ****************************************
56 *****************************************
57 *****************************************
58 ******************************************
59 ******************************************
60 *******************************************
61 *******************************************
62 ********************************************
63 ********************************************
64 ********************************************
65 *********************************************
66 *********************************************
67 **********************************************
68 **********************************************
69 **********************************************
70 **********************************************
71 ***********************************************
72 ***********************************************
73 ***********************************************
74 ************************************************
75 ************************************************
76 ************************************************
77 ************************************************
78 ************************************************
79 *************************************************
80 *************************************************
81 *************************************************
82 *************************************************
83 *************************************************
84 *************************************************
85 *************************************************
86 *************************************************
87 *************************************************
88 *************************************************
89 *************************************************
90 **************************************************
91 *************************************************
92 *************************************************
93 *************************************************
94 *************************************************
95 *************************************************
96 *************************************************
97 *************************************************
98 *************************************************
99 *************************************************
100 *************************************************
101 *************************************************
102 ************************************************
103 ************************************************
104 ************************************************
105 ************************************************
106 ************************************************
107 ***********************************************
108 ***********************************************
109 ***********************************************
110 **********************************************
111 **********************************************
112 **********************************************
113 **********************************************
114 *********************************************
115 *********************************************
116 ********************************************
117 ********************************************
118 ********************************************
119 *******************************************
120 *******************************************
121 ******************************************
122 ******************************************
123 *****************************************
124 *****************************************
125 ****************************************
126 ****************************************
127 ***************************************
128 ***************************************
129 **************************************
130 **************************************
131 *************************************
132 *************************************
133 ************************************
134 ***********************************
135 ***********************************
136 **********************************
137 **********************************
138 *********************************
139 ********************************
140 ********************************
141 *******************************
142 ******************************
143 ******************************
144 *****************************
145 ****************************
146 ***************************
147 ***************************
148 **************************
149 *************************
150 *************************
151 ************************
152 ***********************
153 **********************
154 *********************
155 *********************
156 ********************
157 *******************
158 ******************
159 *****************
160 *****************
161 ****************
162 ***************
163 **************
164 *************
165 ************
166 ************
167 ***********
168 **********
169 *********
170 ********
171 *******
172 ******
173 ******
174 *****
175 ****
176 ***
177 **
178 *
179
180
181
182 *
183 **
184 ***
185 ****
186 *****
187 ******
188 ******
189 *******
190 ********
191 *********
192 **********
193 ***********
194 ************
195 ************
196 *************
197 **************
198 ***************
199 ****************
200 *****************
201 *****************
202 ******************
203 *******************
204 ********************
205 *********************
206 *********************
207 **********************
208 ***********************
209 ************************
210 *************************
211 *************************
212 **************************
213 ***************************
214 ***************************
215 ****************************
216 *****************************
217 ******************************
218 ******************************
219 *******************************
220 ********************************
221 ********************************
222 *********************************
223 **********************************
224 **********************************
225 ***********************************
226 ***********************************
227 ************************************
228 *************************************
229 *************************************
230 **************************************
231 **************************************
232 ***************************************
233 ***************************************
234 ****************************************
235 ****************************************
236 *****************************************
237 *****************************************
238 ******************************************
239 ******************************************
240 *******************************************
241 *******************************************
242 ********************************************
243 ********************************************
244 ********************************************
245 *********************************************
246 *********************************************
247 **********************************************
248 **********************************************
249 **********************************************
250 **********************************************
251 ***********************************************
252 ***********************************************
253 ***********************************************
254 ************************************************
255 ************************************************
256 ************************************************
257 ************************************************
258 ************************************************
259 *************************************************
260 *************************************************
261 *************************************************
262 *************************************************
263 *************************************************
264 *************************************************
265 *************************************************
266 *************************************************
267 *************************************************
268 *************************************************
269 *************************************************
270 **************************************************
271 *************************************************
272 *************************************************
273 *************************************************
274 *************************************************
275 *************************************************
276 *************************************************
277 *************************************************
278 *************************************************
279 *************************************************
280 *************************************************
281 *************************************************
282 ************************************************
283 ************************************************
284 ************************************************
285 ************************************************
286 ************************************************
287 ***********************************************
288 ***********************************************
289 ***********************************************
290 **********************************************
291 **********************************************
292 **********************************************
293 **********************************************
294 *********************************************
295 *********************************************
296 ********************************************
297 ********************************************
298 ********************************************
299 *******************************************
300 *******************************************
301 ******************************************
302 ******************************************
303 *****************************************
304 *****************************************
305 ****************************************
306 ****************************************
307 ***************************************
308 ***************************************
309 **************************************
310 **************************************
311 *************************************
312 *************************************
313 ************************************
314 ***********************************
315 ***********************************
316 **********************************
317 **********************************
318 *********************************
319 ********************************
320 ********************************
321 *******************************
322 ******************************
323 ******************************
324 *****************************
325 ****************************
326 ***************************
327 ***************************
328 **************************
329 *************************
330 *************************
331 ************************
332 ***********************
333 **********************
334 *********************
335 *********************
336 ********************
337 *******************
338 ******************
339 *****************
340 *****************
341 ****************
342 ***************
343 **************
344 *************
345 ************
346 ************
347 ***********
348 **********
349 *********
350 ********
351 *******
352 ******
353 ******
354 *****
355 ****
356 ***
357 **
358 *
359
360 rows selected.
SQL> -
Crosstab Query for Remaining Revenue (Count, If, Date Between )
Hi all, hope you had a great new year.
I am wanting to create a crosstab query for my Projects which shows ProjectID in the row headers and Time Periods split into months quarter or year as the Column Headers using the [DateAgreed] from the Session table.
I have created crosstabs which show revenue from sessions and count of sessions with different time periods but i am trying to make it so that it counts only completed sessions from before the column date, so that i can then multiply by the [SessionCost].
Any ideas guys?
Here's what i have been working with;
TRANSFORM Sum(([tblSession]![SessionCompleted]*[tblProject]![SessionCost])) AS Revenue
SELECT tblProject.ProjectID, tblCompany.CompanyName
FROM (tblSession INNER JOIN tblCompany ON tblSession.CompanyID = tblCompany.CompanyID) INNER JOIN ((tblProject INNER JOIN tblProjectMetrics ON tblProject.ProjectID = tblProjectMetrics.ProjectID) INNER JOIN qryProjectStatus ON tblProject.ProjectID = qryProjectStatus.ProjectID)
ON (tblProject.ProjectID = tblSession.ProjectID) AND (tblCompany.CompanyID = tblProject.CompanyID)
GROUP BY tblProject.ProjectID, tblCompany.CompanyName, tblProject.Total
PIVOT Format([DateAgreed],"yyyy-mm");
Thanks :)Hi Gord0oo,
You could concatenates the data as a result and show in a cell.
TRANSFORM Sum([tblProject]![SessionCost])) & ";" & Sum([tblSession]![SessionCompleted]) AS Revenue
Regards
Starain
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
What is the Count function in formula of Query Design?
What is the Count function in formula of Query Design? Could someone gives an example?
Thanks!Example :
COUNT of
Also, check :
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/7e58e690-0201-0010-fd85-a2f29a41c7af -
Query for collection is not function on SCCM 2012 R2
Hi,
I have a System Center 2012 R2 Config Manager as single management point. The SCCM is already have Endpoint Protection Point role installed. Then I need to create a new collection that contain all SCEP clients, to as deployment target of a rule and policy.
I've try to create a query-based collection, with the following query language :
select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System inner join SMS_G_System_INSTALLED_SOFTWARE on SMS_G_System_INSTALLED_SOFTWARE.ResourceId
= SMS_R_System.ResourceId where SMS_G_System_INSTALLED_SOFTWARE.ProductName = "System Center 2012 Endpoint Protection"
But after the collection is created, none of the emerging client that have SCEP installed.
Earlier I have apply this query on the SCCM 2012 SP1 environtment, and it is work. But now I have migrate to the SCCM 2012 R2, and this query is seems not function on R2 version.
Is there difference query language between SCCM 2012 SP1 and R2?
Thanks.
Regards, Bar WaelahHi,
I saw System Center 2012 Endpoint Protection is under Installed Applications (64) node when I open Resource Explorer on a computer that installed System Center 2012 Endpoint Protection.
So I edited your query, then these computers appeared on the collection.
select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System inner join SMS_G_System_ADD_REMOVE_PROGRAMS_64 on SMS_G_System_ADD_REMOVE_PROGRAMS_64.ResourceID
= SMS_R_System.ResourceId where SMS_G_System_ADD_REMOVE_PROGRAMS_64.DisplayName like "System Center 2012 Endpoint Protection"
Best Regards,
Joyce Li
We
are trying to better understand customer views on social support experience, so your participation in this
interview project would be greatly appreciated if you have time.
Thanks for helping make community forums a great place. -
How to write sql query for counting pairs from below table??
Below is my SQL table structure.
user_id | Name | join_side | left_leg | right_leg | Parent_id
100001 Tinku Left 100002 100003 0
100002 Harish Left 100004 100005 100001
100003 Gorav Right 100006 100007 100001
100004 Prince Left 100008 NULL 100002
100005 Ajay Right NULL NULL 100002
100006 Simran Left NULL NULL 100003
100007 Raman Right NULL NULL 100003
100008 Vijay Left NULL NULL 100004
It is a binary table structure.. Every user has to add two per id under him, one is left_leg and second is right_leg... Parent_id is under which user current user is added.. Hope you will be understand..
I have to write sql query for counting pairs under id "100001". i know there will be important role of parent_id for counting pairs. * what is pair( suppose if any user contains both left_leg and right_leg id, then it is called pair.)
I know there are three pairs under id "100001" :-
1. 100002 and 100003
2. 100004 and 100005
3. 100006 and 100007
100008 will not be counted as pair because it does not have right leg..
But i dont know how to write sql query for this... Any help will be appreciated... This is my college project... And tommorow is the last date of submission.... Hope anyone will help me...
Suppose i have to count pair for id '100002'. Then there is only one pair under id '100002'. i.e 100004 and 100005Sounds like this to me
DECLARE @ID int
SET @ID = 100001--your passed value
SELECT left_leg,right_leg
FROM table
WHERE (user_id = @ID
OR parent_id = @ID)
AND left_leg IS NOT NULL
AND right_leg IS NOT NULL
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
can i achieve effect of counting of 1 to 50 (say) by a single query?
eg. i wan a query for which output is:-
1
2
3
4
50
plz. note that no other table is available for joining purposes.An effective way of doing the same is using a query like:
select rownum
from (
select 1, 2, 3, 4, 5, 6, 7, 8
from dual
group by cube (1, 2, 3, 4, 5, 6, 7, 8)
The advantage of it is not needing a table with x rows to get number you want; also, this query as it is produces 2 ^ 10, i.e. 2 to 10th power, that gives us 1024 (number of rows, so our "maximum" value). If you need higher numbers than that, just ad to the select and group by cube more numbers, like follows:
select rownum
from (
select 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
from dual
group by cube (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
This would give us a maximum value of 2 to 11th power, or 2048.
I got this code on asktom.oracle.com, a very valuable resource!
Regards,
Bruno
Maybe you are looking for
-
How to have custom control in DataGridView display object's value?
I have a sample project located here The project has a main form `Form1` where the user can enter customers in a datagridview. The `CustomerType` column is a custom control and when the user clicks the button, a search form `Form2` pops up. The searc
-
Hello, for the past year or so I have been having intermittent internet connectivity issues. It appears to happen completely randomly, sometimes it will work flawlessly for a few weeks and then there are days where it just drops nonstop every 5 minut
-
Web.show_document does not open browser anymore
We upgraded our production database over the weekend from 10g to 11g. When it was still 10g, our Forms application used to open a PDF embedded in IE. After moving to 11g, it does not open IE anymore and shows no error messages. Clicking the button wi
-
I had hoped to figure this out without pestering anyone, but I just got confused. I have a Dual 2 G5(8-dimm) with a Radeon 9600xt and an aluminum studio 20' display. I believe I have a second display port that is DVI (?) and not ADC (did they come wi
-
Hi! I have a problem with my psc 1315. Sorry that I don't speak english ( I speak italian), I will tray to explain the problem: on my printer there is a light in "verifica carta" (check paper). The printer did not have problem with paper since now an