Find Duplicate Query MySQL Syntax
There is a "find duplicates" query in SQL that is very useful
but I'm not sure what the syntax is for MySQL. It probably has
something to do with select distinct, group by but I'm not used to
to using these.
This is one that finds all duplicates of [FULLNAME]
SELECT CONTACTS.*
WHERE (((CONTACTS.FULLNAME) In (SELECT [FULLNAME] FROM
[CONTACTS] As Tmp GROUP BY [FULLNAME]
HAVING Count(*)>1 )))
ORDER BY CONTACTS.FULLNAME, CONTACTS.COMPANY
Does anyone know?
RichardODreamweaver wrote:
> There is a "find duplicates" query in SQL that is very
useful but I'm not sure
> what the syntax is for MySQL.
SELECT COUNT(*) AS repetitions, FULLNAME, COMPANY
FROM CONTACTS
GROUP BY FULLNAME, COMPANY
HAVING repetitions > 1
It's not something I have used myself, but I got it from
MySQL Cookbook
by Paul DuBois, published by O'Reilly. I have the first
edition, which
covers MySQL 4.0. I think the second edition covers MySQL
5.0.
If you're using MySQL on a regular basis, you or your
employer should
buy it immediately. It will solve most of your problems and
repay its
cost many times over.
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Similar Messages
-
How to find duplicate row in sql query?
Hi All,
Please solve my query, find duplicate row and how to count its. your suggestion would be greatly appreciated.You can use group by and having.
SQL> WITH t
2 AS (SELECT LEVEL id
3 FROM DUAL
4 CONNECT BY LEVEL <= 5
5 UNION ALL
6 SELECT LEVEL + 2
7 FROM DUAL
8 CONNECT BY LEVEL <= 3)
9 SELECT *
10 FROM t;
ID
1
2
3
4
5
3
4
5
8 rows selected.
SQL> WITH t
2 AS (SELECT LEVEL id
3 FROM DUAL
4 CONNECT BY LEVEL <= 5
5 UNION ALL
6 SELECT LEVEL + 2
7 FROM DUAL
8 CONNECT BY LEVEL <= 3)
9 SELECT id, COUNT (*)
10 FROM t
11 GROUP BY id
12 HAVING COUNT (*) > 1;
ID COUNT(*)
3 2
4 2
5 2
SQL> -
Help with Finding Duplicate records Query
HI,
I am trying to write a query that will find duplicate records/cases.
This query will be used in a report.
So, here are the requirements:
I need to find duplicate cases/records based on the following fields:
DOB, DOCKET, SENT_DATEI was able to do that with the following query. The query below is able to give me all duplicate records based on the Criteria above
SELECT DEF.BIRTH_DATE DOB,
S.DOCKET DOCKET,
S.SENT_VIO_DATE SENT_DATE, COUNT(*)
FROM SENTENCES S,
DEFENDANTS DEF
WHERE S.DEF_ID = DEF.DEF_ID
AND S.CASE_TYPE_CODE = 10
GROUP BY DEF.BIRTH_DATE, S.DOCKET, S.SENT_VIO_DATE
HAVING COUNT(*) > 1;
//I AM GOING TO CALL THIS QUERY 'X'Now, the information to be displayed on the report: defendants Name, DOB, District, Docket, Def Num, Sent Date, and PACTS Num if possible.
The problem that I need help on is how to combine those queries together (what I mean is a sub query). the 'X' query returns multiple values. please have a look at the comments on the query below to see what I'm trying to achieve.
here is the main query:
SELECT INITCAP(DEF.LAST_NAME) || ' ' || INITCAP(DEF.FIRST_NAME) || ' ' || INITCAP(DEF.MIDDLE_NAME) DEFENDANT_NAME,
DEF.BIRTH_DATE DOB,
TRIM(DIST.DISTRICT_NAME) DISTRICT_NAME,
S.DOCKET DOCKET,
S.DEF_NUM DEF_NUM,
S.SENT_VIO_DATE SENT_DATE,
DEF.PACTS_ID PACTS_NUM
FROM USSC_CASES.DEFENDANTS DEF,
USSC_CASES.SENTENCES S,
LOOKUP.DISTRICTS DIST
WHERE DEF.DEF_ID = S.DEF_ID
AND S.DIST_ID = DIST.USSC_DISTRICT_ID
AND S.CASE_TYPE_CODE = 10
AND S.USSC_ID IS NOT NULL
AND // what i'm trying to do is: DOB, DOCKET, SENT_DATE IN ('X' QUERY), is this possible ??
ORDER BY DEFENDANT_NAME; thanks in advance.
I am using Oracle 11g, and sql developer.
if my approach doesn't work, is there a better approach ?
Edited by: Rooney on Jul 11, 2012 3:50 PMIf I got it right, you want to join table USSC_CASES.DEFENDANTS to duplicate rows in USSC_CASES. If so:
SELECT INITCAP(DEF.LAST_NAME) || ' ' || INITCAP(DEF.FIRST_NAME) || ' ' || INITCAP(DEF.MIDDLE_NAME) DEFENDANT_NAME,
DEF.BIRTH_DATE DOB,
TRIM(DIST.DISTRICT_NAME) DISTRICT_NAME,
S.DOCKET DOCKET,
S.DEF_NUM DEF_NUM,
S.SENT_VIO_DATE SENT_DATE,
DEF.PACTS_ID PACTS_NUM
FROM USSC_CASES.DEFENDANTS DEF,
SELECT *
FROM (
SELECT S.*,
COUNT(*) OVER(PARTITION BY DEF.BIRTH_DATE, S.DOCKET, S.SENT_VIO_DATE) CNT
FROM USSC_CASES.SENTENCES S
WHERE CNT > 1
) S,
LOOKUP.DISTRICTS DIST
WHERE DEF.DEF_ID = S.DEF_ID
AND S.DIST_ID = DIST.USSC_DISTRICT_ID
AND S.CASE_TYPE_CODE = 10
AND S.USSC_ID IS NOT NULL
ORDER BY DEFENDANT_NAME;If you want to exclude duplicates from the query and do not care which row out of duplicate rows to choose:
SELECT INITCAP(DEF.LAST_NAME) || ' ' || INITCAP(DEF.FIRST_NAME) || ' ' || INITCAP(DEF.MIDDLE_NAME) DEFENDANT_NAME,
DEF.BIRTH_DATE DOB,
TRIM(DIST.DISTRICT_NAME) DISTRICT_NAME,
S.DOCKET DOCKET,
S.DEF_NUM DEF_NUM,
S.SENT_VIO_DATE SENT_DATE,
DEF.PACTS_ID PACTS_NUM
FROM USSC_CASES.DEFENDANTS DEF,
SELECT *
FROM (
SELECT S.*,
ROW_NUMBER() OVER(PARTITION BY DEF.BIRTH_DATE, S.DOCKET, S.SENT_VIO_DATE ORDER BY 1) RN
FROM USSC_CASES.SENTENCES S
WHERE RN = 1
) S,
LOOKUP.DISTRICTS DIST
WHERE DEF.DEF_ID = S.DEF_ID
AND S.DIST_ID = DIST.USSC_DISTRICT_ID
AND S.CASE_TYPE_CODE = 10
AND S.USSC_ID IS NOT NULL
ORDER BY DEFENDANT_NAME;SY. -
Script to find duplicate index and how can we tell if an index is REALLY a duplicate?
Does any one have script to find duplicate index? and how can we tell if an index is REALLY a duplicate?
RahulOne more written by Itzik Ben-Gan
The first query finds exact matches. The indexes must have
the same key columns in the same order, and the same included columns but in any order.
These indexes are sure targets for elimination. The only caution would be to check for index hints.
-- exact duplicates
with indexcols as
select object_id as id, index_id as indid, name,
(select case keyno when 0 then NULL else colid end as [data()]
from sys.sysindexkeys as k
where k.id = i.object_id
and k.indid = i.index_id
order by keyno, colid
for xml path('')) as cols,
(select case keyno when 0 then colid else NULL end as [data()]
from sys.sysindexkeys as k
where k.id = i.object_id
and k.indid = i.index_id
order by colid
for xml path('')) as inc
from sys.indexes as i
select
object_schema_name(c1.id) + '.' + object_name(c1.id) as 'table',
c1.name as 'index',
c2.name as 'exactduplicate'
from indexcols as c1
join indexcols as c2
on c1.id = c2.id
and c1.indid < c2.indid
and c1.cols = c2.cols
and c1.inc = c2.inc;
The second variation of this query finds partial, or duplicate, indexes
that share leading key columns, e.g. Ix1(col1, col2, col3) and Ix2(col1, col2)
would be considered duplicate indexes. This query only examines key columns and does not consider included columns.
These types of indexes are probable dead indexes walking.
-- Overlapping indxes
with indexcols as
select object_id as id, index_id as indid, name,
(select case keyno when 0 then NULL else colid end as [data()]
from sys.sysindexkeys as k
where k.id = i.object_id
and k.indid = i.index_id
order by keyno, colid
for xml path('')) as cols
from sys.indexes as i
select
object_schema_name(c1.id) + '.' + object_name(c1.id) as 'table',
c1.name as 'index',
c2.name as 'partialduplicate'
from indexcols as c1
join indexcols as c2
on c1.id = c2.id
and c1.indid < c2.indid
and (c1.cols like c2.cols + '%'
or c2.cols like c1.cols + '%') ;
Be careful when dropping a partial duplicate index if the two indexes differ greatly in width.
For example, if Ix1 is a very wide index with 12 columns, and Ix2 is a narrow two-column index
that shares the first two columns, you may want to leave Ix2 as a faster, tighter, narrower index.
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
How do I find duplicate words in a Numbers spreadsheet?
Hello, I've created my first document on Numbers and am trying to figure out how to find duplicate words. Ideally, a list of words that repeat in the document and how many times. Is this possible? Thank you in advance for the advice
It's easy enough to find and count duplicate entries, especially if they are all in a single column, but if you want to count individual words within multi word entries, the problem is more complicated.
Here's an example for the 'simple' case, using a familiar 155 word passage from English literature.
The words in the passage are separated into a single line for each word, and stripped of all punctuation. This may be done in Pages, or in Text edit, or in pretty much any word processing software or text editor. Paste the passage into a WP or text document, then use the application's Find/Replace feature to replace all of the spaces with returns. I would also do a second pass replacing all double returns with single returns, then repeat that until Find/Replace reported replacing zero occurrences.
Punctuation was stripped using Find/Replace
The prepared list was pasted into column A of a Numbers table.
Formulas:
B2: =COUNTIF($A$1:A2,A2)
C2: =IF(AND(B>1,B=COUNTIF($A,A2)),ROW()-1,999999)
Fill both down their respective columns to the end of the table.
The small table is inserted as a Basic table using the Tables button. It contains a Header row, but no Header columns.
Formula:
A2: =IFERROR(OFFSET(Table 1 :: $A$1,SMALL(Table 1 :: $C,ROW()-1),COLUMN()-1),"")
Fill right into B2, then fill both down to the end of the table.
Descriptions of the functions used, along with their syntax and at least one example of their use in a table are available in the Numbers '09 User Guide, which may be downloaded via the Help menu in Numbers.
Regards,
Barry
PS: Regards to the late Mr. Shakespeare, and thank you for providing the text used. -
Unable to find Cube / Query in Catalog (Designer)
Hello,
Our current environment consists of BW Queries which are access by BO Universes. When creating a Universe we were able to see all queries but since we did some changes to the MP and cubes we don't see the queries anymore from BO Side.
Also the current reports fail with an error "Unable to find Cube <QueryName> in catalog".
The queries used in the universes are still visible and accessible in BEx Analyzer.
What I tried so far (with a super user) is:
1. Generate query again -> no change
2. Save the query again -> no change
3. Remove the flag u201CAllow external Access to this queryu201D, save query and flag the option again -> no change
4. Activate the MultiProvider again -> no change
5. Copy the query to another query u2013
-> New query is accessible. This means the MP and cubes are not the reason. It seems like the query is gone in an inactive modeu2026
6. Used BAPI BAPI_MDPROVIDER_GET_CUBES to get the list of accessible queries.
-> I see the same list as in BO. Most queries are missing. The ones that are in the list disappear whenever we try to access these queries from BO.
Did anyone encounter the same issue and was able to solve it?
Environment: SAP BI 7.1 EHP1 SP5, BO XI 3.1 SP2(1.7).
Thanks in advance.
ManuHi Manu,
your are talking about universe designer here - right?
We have the same behaviour currently in Crystal 2008 designer and universe designer.
In both we can see the same but not the complete list of queries.
We made sure the "allow external access" option is set in BEX.
We resolved both issues with same root cause : adjust Query properties -> Req. status -> ...
Pls refer to thread Unable to find BW Query while creating connection with universe designer as well - thanks Ingo !
- logon to the SAP system
- start transaction RSRT
- enter the technical name of the BW query in the syntax CUBE/QUERY
- click Properties
- set the second item called Req.Status.
- set that one to 0
Let us know if this helped !
Holger
Edited by: Holger Brasch on Mar 26, 2010 11:58 PM -
Finding duplicate values in a column with different values in a different c
I'm finding duplicate values in a column of my table:
select ba.CLAIM_NUMBER from bsi_auto_vw ba
group by ba.CLAIM_NUMBER
having count(*) > 1;
How can I modify this query to find duplicate values in that column where I DON'T have duplicate values in a different specific column in that table (the column CLMT_NO in my case can't have duplicates.)?Well, you can use analytics assuming you don't mind full scanning the table.....
select
count(owner) over (partition by object_type),
count(object_type) over (partition by owner)
from all_objects;You just need to intelligently (i didn't here) find your "window" (partition clause) to sort the data over, then make use of that (the analytics would be in a nested SQL and you'd then evaluate it in outside).
Should be applicable if i understand what you're after.
If you post some sample data we can mock up a SQL statement for you (if what i tried to convey wasn't understandable). -
How to create an activity when system finds duplicate record!!
Hi CRM Experts,
I am working on CRM 5.0. We are uploading contact details to CRM through ELM.
Here My queries are:
1) How to create An Activity when system finds duplicate record?
2) By using ELM we can create BP with Activities and BP with Leads. But Here, my scenario is we have to Create BP with leads and Acivities. can any one help me on these areas?
Thank in Advance.
SreeHi Sree,
I can help you with your first query.
When the system finds a duplicate record then either the system stops working further or proceeds with the error free record.
So once the duplicate entry is found only the first record will be considered and not the second or the duplicate record.
Regards,
Rekha Dadwal
Kindly reward with points if usefull !!!! -
I want to find duplicate names from my database I wrote the following query. But it is displaying more that existing records. I guess it is taking cartesian product.
select a.name from emp from emp a,emp b where a.name=b.name;
can anyone correct this query.
I want to display all the duplicate records having same names...
for example for the following table. I want to display result having same dname like
DEPTNO DNAME LOC
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
50 SALES hyd
output should be
30 sales chicago
50 sales hydWelcome to OTN.
From your initial sample data - i didn't find anything duplicate. They all are unique if you consider deptno.
But, i assume you have plenty of redundant data. So, your query may be look like ->
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
Elapsed: 00:00:00.16
satyaki>
satyaki>
satyaki>create table dup_emp
2 as
3 select k.*
4 from (
5 select * from emp
6 union all
7 select * from emp
8 where rownum < 6
9 ) k;
Table created.
Elapsed: 00:00:03.90
satyaki>
satyaki>
satyaki>select * from dup_emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
9999 SATYAKI SLS 7698 02-NOV-08 55000 3455 10
7777 SOURAV SLS 14-SEP-08 45000 3400 10
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 4450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 7000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
9999 SATYAKI SLS 7698 02-NOV-08 55000 3455 10
7777 SOURAV SLS 14-SEP-08 45000 3400 10
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
18 rows selected.
Elapsed: 00:00:00.32
satyaki>
satyaki>
satyaki>select empno, count(empno)
2 from dup_emp
3 group by empno
4 having count(empno) > 1;
EMPNO COUNT(EMPNO)
9999 2
7777 2
7521 2
7566 2
7654 2
Elapsed: 00:00:00.11
satyaki>
satyaki>
satyaki>Regards.
Satyaki De. -
Hi all,
how to find physical query from report here m checking like Administrator->manage session--> report-->view log
+++Administrator:3220000:3220011:----2011/01/03 02:51:43
-------------------- SQL Request:
+++Administrator:3220000:3220011:----2011/01/03 02:51:43
-------------------- General Query Info:
Repository: Star, Subject Area: AAA, Presentation: AAA
+++Administrator:3220000:3220011:----2011/01/03 02:51:43
-------------------- Cache Hit on query:
Matching Query: Created by: Administrator
+++Administrator:3220000:3220011:----2011/01/03 02:51:43
-------------------- Query Status: Successful Completion
+++Administrator:3220000:3220011:----2011/01/03 02:51:43
-------------------- Physical Query Summary Stats: Number of physical queries 1, Cumulative time 0, DB-connect time 0 (seconds)
+++Administrator:3220000:3220011:----2011/01/03 02:51:43
-------------------- Rows returned to Client 6
+++Administrator:3220000:3220011:----2011/01/03 02:51:43
-------------------- Logical Query Summary Stats: Elapsed time 0, Response time 0, Compilation time 0 (seconds)
but here m not able to find database query..how to find that query plz help
Edited by: Sonal on Jan 3, 2011 5:29 AM
Edited by: Sonal on Jan 3, 2011 5:30 AM
Edited by: Sonal on Jan 3, 2011 5:30 AMHi,
as Daan said, set the variable in Advanced tab but not on loglevel..
because, our problem is to bypass the bi-server cache.
Do this:
1. Go to Advanced tab.
2. In Prefix field(scroll down to see this field) , enter this:
SET DISABLE_CACHE_HIT = 1;
Note: Make sure that you're ended up above statement with semicolon and do not click on Set SQL option...
3. Save report, then run it..
4. After you see the query, i recommend you to take take out that prefix tag then save it again.. -
How to find a query name from report name
I have a report in my system with the name AQICMM==========P2============ . I believe this was created from a query. How to find the query corresponding to this report ? I need to change the logic for certain columns of the report. How to know if this was created from SQVI or SQ01 or any other transaction.
THanks.Found it..Query name is P2. It was in a different query area..Standard area and not custom area where I was initially looking at.
Edited by: Shareen Hegde on Aug 22, 2008 5:14 PM -
How can I find duplicate photos without going through all 5000 one at a time?
How can I find duplicate photos withough going through all 5000 one by one? I have numerous duplications and used to be able to click on Edit and Find Duplicates and could clean up all the duplicates easily. Now that option is gone. I still have lots to delete.
I do backup everything using Carbonite.Please don't tell me it is bad, too :-) Also, especially with photo files, I do have other backups of those I am concerned about. Probably not the best in the world, but a log better than many people who I know about.
Again, I really have not seen any problems with MacKeeper. I imagine that if people do not read and follow instructions, they could have problems. For example, it is possible to scan all your files and see them in order of size. If you start deleting things, without knowing what you're deleting, you could cause trouble. Even when the computer scans for so-called junk files, you can look at them and decide for yourself if they are truly junk. I've never seen any that were not.
So, I will look at the complaints anyway to see them. I am open to change, although I hope I do not need to drop Mackeeper as it does things like keeping tracking of applications updates that I need. Please note that I definitely am not a MacKeeper employee or anything close. Just using it and happy with the the results.
I did download the recommend file for finding photo dupes and ran it. There were very few duplicates, in any case, As I said before, the MacKeeper dupe finder was very slow when I ran it over ALL my files. That was a year ago and it did find many non-text dupes. -
How do I find duplicate songs/files in iTunes 11?
How do I find duplicate songs/files in iTunes 11?
Earlier versions of iTunes had a simple menu option to click on.
All duplicates would then be listed. Cannot find this option now.
Regards ..... blayk.If you want to free up your memory, maybe first checking to see if you got duplicates. -
From the File menu in iTunes, choose Show Duplicates. iTunes will then list all of the duplicate titles in your library.
If you delete a music in the iTunes folder, then when you try to play that particular music in your iTunes, it won't work as iTunes wouldn't be able to find it. However, when you import music on to your computer, always import straight into your iTunes, no where else. -
I have iTunes version 10.03 which I love but my iPad Apple mini has iOS 7 but I don't understand the new iTunes what is the cloud shown next to the music and how can I find duplicates can anyone help me navigate the new iTunes and will the new version sync with my iPod Classic which is 4 years old
The main differences between iTunes 11 and earlier versions are the loss of coverflow and ability to have multiple windows open.
In Windows, you can restore much of the look & feel of iTunes 10.7 with these shortcuts:
ALT to temporarily display the menu bar
CTRL+B to show or hide the menu bar
CTRL+S to show or hide the sidebar
CTRL+/ to show or hide the status bar (won't hide for me on Win XP)
Click the magnifying glass top right and untick Search Entire Library to restore the old search behaviour
Use View > Hide <Media Kind> in the cloud or Edit > Preferences > Store and untick Show iTunes in the cloud purchases to hide the cloud items. The second method eliminates the cloud status column (and may let iTunes start up more quickly)
If you don't like having different coloured background & text in the Album (Grid) view use Edit > Preferences > General and untick Use custom colours for open albums, movies, etc.
With iTunes 11.0.3 and later you can enable artwork in the Songs view from View > Show View Options (CTRL+J) making it more like the old Album List view
View > Show View Options (CTRL+J) also contains options to change the sorting of grid based views
The cloud icons give you access to stream or download any qualifying past purchases that you don't currently have downloaded to the library.
Regarding duplicates, things haven't really changed. Apple's official advice is here... HT2905 - How to find and remove duplicate items in your iTunes library. It is a manual process and the article fails to explain some of the potential pitfalls.
Use Shift > View > Show Exact Duplicate Items to display duplicates as this is normally a more useful selection. You need to manually select all but one of each group to remove. Sorting the list by Date Added may make it easier to select the appropriate tracks, however this works best when performed immediately after the dupes have been created. If you have multiple entries in iTunes connected to the same file on the hard drive then don't send to the recycle bin. Use my DeDuper script if you're not sure, don't want to do it by hand, or want to preserve ratings, play counts and playlist membership. See this thread for background and please take note of the warning to backup your library before deduping.
(If you don't see the menu bar press ALT to show it temporarily or CTRL+B to keep it displayed)
Yes, iTunes 11 will support your iPod classic.
tt2 -
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>
Maybe you are looking for
-
How to populate the condition tables of CRM 7.0
Hello Friends, How to populate values in CND* tables , i assume these are the tables that hold the conditions. Thanks and Regards, Vasu
-
Can't open admin account !
Sorry- now I'm really crawling up the wall. I have not made any changes to my admin account other than changing the name of it. The password works fine to sign in, but when I go to make a change (like turning on the FireaVault) it will not let work a
-
We're using Pages to develop PDF documents. Is there a way to incorporate video (flv, swf, mov, etc) in PDF documents? When I export to PDF all that appears is a black placeholder where the video originally resided.
-
JSF url-pattern *.jsf problem
Hi all, I am working in a project to add the jsf page in the existing jsp application. It uses Apache Tomcat 6.0.18 as the server and eclipse for coding. I created a jsf page named index.jsp and I added the code in web.xml as follows <servlet-mapping
-
The crop icon on the full edit tool bar.
The crop icon on the full edit tool bar is missing. It used to be there? How can I add it back?