How to write a query for this data?
In this table, I dob column that is of type DATE, for example, 12 January 89 I want output like this
Day of the year
January 12, 89 Thusrs_day
January 12, 90 Friday
up to
12 January 14 Sunday
Select add_months (d, ((level*12)-12)), to_char (add_months (d, ((level*12)-12)), 'DY')
de)
Select d double to_date('12-jan-89','dd-mon-rr')
)
connect by level<=>=>
----------------------------- ------------------------------
12.01.1989 GAME
12.01.1990 FRI
12.01.1991 SAT
12.01.1992 SUN
12.01.1993 MAR
12.01.1994 SEA
12.01.1995 GAME
12.01.1996 FRI
12.01.1997 SUN
12.01.1998 LUN
MAR 12.01.1999
12.01.2000 SEA
12.01.2001 FRI
12.01.2002 SAM
12.01.2003 SUN
12.01.2004 LUN
12.01.2005 WED
12.01.2006 GAME
12.01.2007 FRI
SAM 12.01.2008
12.01.2009 LUN
12.01.2010 MAR
12.01.2011 WED
12.01.2012 GAME
24 selected lines
----
Ramin Hashimzade
Tags: Database
Similar Questions
-
How to write a query for the data exchange between two columns?
How to write a query for the data exchange between two columns?
I tried a request, does NOT work.
Thank you.update tmp t1 set t1.m1=t1.m2 and t1.m2=(select t2.m1 from tmp t2 where t2.student_id = t1.student_id)
Published by: user533361 on October 23, 2009 14:04Just plain and simple:
update tmp t1 set t1.m1=t1.m2, t1.m2=t1.m1 /
SY.
-
How to write a query for the given scenario?
Hi all
I have two tables EMP, DEPT with data below.
EMP TABLE: -.
SAL DEPID EMPLOYMENT ENAME EID
111 RAM 1500 10 MANAGER
222 SAM ASST MANAGER 2000 20
KALA 333 2500 10 REGISTRAR
444. BIMA 20 3000 MANAGER
CHALA 555 MANAGER 3500 30
RANI 666 ASST MANAGER 4000 10
777 KAMAL MANAGER 2400 10
DEPT TABLE: -.
DEPID DNAME
XX 10
AA 20
30 ZZ
Q1: I want the sum of the salary of each Department and for the particular job. Here, in each Department manager, Assistant Manager, clerk positions are there.
I want to display the result as below...
10-20-30 JOBS
--------------------------------------------------------------------------
MANAGER OF 3900 3000 3500
ASST MANAGER 4000 2000 NULL
THE CLERK 2500 NULL NULL
Please tell me how to write a sql query?
Thank you
SAISQL> SELECT job, 2 MAX(DECODE(deptno, 10, sum_sal)) "10", 3 MAX(DECODE(deptno, 20, sum_sal)) "20", 4 MAX(DECODE(deptno, 30, sum_sal)) "30" 5 FROM (SELECT deptno, job, SUM(sal) sum_sal FROM emp GROUP BY deptno, job) 6 GROUP BY job; JOB 10 20 30 --------- ---------- ---------- ---------- CLERK 1300 1900 950 SALESMAN 5600 PRESIDENT 5000 MANAGER 2450 2975 2850 ANALYST 6000 SQL>
-
How to write a SQL for this condition?
I have a table with columns v_sub, v_visit, and T_DATE and the structure is like this
v_sub v_visit T_DATE
1 visit-1 01 - mar - 09
1 visit-2 05 - mar - 09
1 visit-3 17 - mar - 09
2-visit-1-4 February 09
2 visit-2 12 - mar - 09
2 visit-3 20 - mar - 09
I want to write a query that control weather it is in chronological order or not. (for v_sub, v_visit and T_DATE must be in chronological order as above)
and I want to check the condition as below:
v_sub v_visit T_DATE
1 visit-1 01 - mar - 09
1 visit-2 5 February 09
1 visit-3 17 - mar - 09
2-visit-1-4 February 09
2 visit-2 12 January 09
2 visit-3 20 - mar - 09
Thanks in advanceUse the LAG function to get previous date
SQL> -- sample data SQL> with t 2 as 3 ( 4 select 1 v_sub, 'visit-1' v_visit, to_date('01-mar-09','dd-mon-yy') v_date from dual union all 5 select 1, 'visit-2', to_date('05-mar-09','dd-mon-yy') from dual union all 6 select 1, 'visit-3', to_date('17-mar-09','dd-mon-yy') from dual union all 7 select 2, 'visit-1', to_date('04-feb-09','dd-mon-yy') from dual union all 8 select 2, 'visit-2', to_date('12-mar-09','dd-mon-yy') from dual union all 9 select 2, 'visit-3', to_date('20-mar-09','dd-mon-yy') from dual 10 ) 11 -- end of sample data 12 select v_sub, v_visit, v_date, lag(v_date) over(partition by v_sub order by v_visit, v_date) v_previous_date 13 from t 14 / V_SUB V_VISIT V_DATE V_PREVIOU ---------- ------- --------- --------- 1 visit-1 01-MAR-09 1 visit-2 05-MAR-09 01-MAR-09 1 visit-3 17-MAR-09 05-MAR-09 2 visit-1 04-FEB-09 2 visit-2 12-MAR-09 04-FEB-09 2 visit-3 20-MAR-09 12-MAR-09 6 rows selected.
Now you can check if the previous_date is less than T_DATE
-
Hi friend
I have a requirement to fill what I want your help...... I create the sample table and sample data here.
My table is like this:
------------------------------
create table test1
(docid number (10),)
doctyp varchar2 (10),
billno varchar2 (10),
prnno varchar2 (10),
amount number (10)
);
My data are:
--------------------------
insert into test1 values (D0001, 'BNP05', '101', 'PRN01', 1000);
insert into test1 values (D0001, 'BNP05', '101', 'PRN02', 1000);
insert into test1 values (D0001, 'BNP05', '101', 'PRN03', 1000);
insert into test1 values (D0002, 'BNP05', '102', "PR01", 100);
My o/p expected:
-----------------------------
DOCID DOCTYP BILLNO PRNNO AMOUNT
================================================
D0001 BNP05 101 PRN01 1000
D0001 BNP05 PRN02 101 0
D0001 BNP05 PRN03 101 0
D0002 BNP05 PR01 101 100
If you see, I don't see how repeatly for DOCID, DOCTYP, BILLNO combination...
How to get there...?
Thanks in advanceHello
Do you want something like this:
SQL> select DOCID, DOCTYP, BILLNO, prnno, 2 case 3 when row_number() over(partition 4 by 5 docid,doctyp,billno 6 order by prnno) = 1 7 then amount 8 else null 9 end as amount 10 from test1 11 order by docid,doctyp,billno; DOCID DOCTYP BILLNO PRNNO AMOUNT ---------- ---------- ---------- ---------- ---------- 1 BNP05 101 PRN01 1000 1 BNP05 101 PRN02 1 BNP05 101 PRN03 2 BNP05 102 PR01 100 SQL>
-
How to write a query for the following scenario
Hi I have a table as follows which have values of column as below
I want to find the values 7 and 15 on each line together in one of the columns of 4 to 8.column1 column2 column3 column4 column5 column6 column7 column8 10000 10 1 7 15 10 9 0 10001 11 2 7 19 0 8 1 10002 12 3 9 8 7 15 0
Here, in case I get a first and third ranks.
(Column1, Column2, Column3) is the primary key for the table
Help, please
Henawith data as ( select 10000 as column1, 10 as column2, 1 as column3, 7 as column4, 15 as column5, 10 as column6, 9 as column7, 0 as column8 from dual union all select 10001, 11, 2, 7, 19, 0, 8, 1 from dual union all select 10002, 12, 3, 9, 8, 7, 15, 0 from dual ) select * from data where 7 in (column4, column5, column6, column7, column8) and 15 in (column4, column5, column6, column7, column8) / COLUMN1 COLUMN2 COLUMN3 COLUMN4 COLUMN5 COLUMN6 COLUMN7 COLUMN8 ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- 10000 10 1 7 15 10 9 0 10002 12 3 9 8 7 15 0
Edited because requirement changed while displaying the solution
Published by: Cyn on October 30, 2009 15:27
-
How to write a query for having given the order number
Hello
We use 10 gr 2:
I have data in the following format, I want to group_nr based on month_nr (and it may start from any month)
month_nr group_nr
4 1
4 1
5 2
5 2
5 2
5 2
5 2
6 3
6 3
6 3
....
Thank you
Select month_nr,
DENSE_RANK() over (order by month_nr) group_nr
FROM MyTable
----
Ramin Hashimzade
-
How to write a script for date get to the Clipboard
Hi experts,
How to write a script for date get to the Clipboard.
the date format will be like this:
05 - may
respect of
John
Thanks guys, thanks Sanon
I finally use the .bat doc
like this:
@@echo off
for /f "delims =" % in (' wmic OS Get localdatetime ^ | find ".") "") Set "dt = %% a"
the value "YYYY = % dt: ~ 0, 4%.
the value "MM = % dt: ~ 4, 2%.If MM % is 01 set MM = January
If % MM == 02 set MM = February
If MM % is MM value = March 03
If MM % is 04 MM value = April
If MM % is 05 MM value = may
If MM % is 06 MM value = June
If MM % == 07 set MM = July
If MM % is MM value = August 08
If MM % is MM value = September 09
If MM % is 10 MM value = October
If MM % is 11A set MM = November
If MM % is game MM 12 = Decemberthe value "DD = % dt: ~ 6, 2%.
the value "HH = % dt: ~ 8, 2%.
the value "Min = % dt: ~ 10, 2%.
Set "s = % dt: ~ 12, 2%.Echo DD - MM HH % %% % Min | Clip
It works
respect of
John
-
How to write a query to return rows with the varchar column that contains even a single occurrence of the characters, such as Ÿ and
I have a table whose columns with values such as
MINNEAŸPOLIS and ¿VV ¿A
Only the characters that are allowed in this column are alphabets, numbers, spaces, points and supports.
Please help to write a SQL SELECT with Regexp_like query or any other option.
Thanks to you all! Under query worked for me. Thank you Frank to explain the concept of hooks inside regexp_like.
SELECT * FROM testspecial, WHERE REGEXP_LIKE (sampletext, "[^] ^ A - Z ^ a - z ^ 0-9 ^ [^.]") ^ {^} ^]') ;
-
How to write the query option in expdp
Hi Please someone help me how to write the query option in expdp... .in expdp using the query option...
where AM columnname between 5 May 12 02:57:00.000' and ' 02:59:59.999 6 May 12: ';
Please do what is necessary...Pavan Kumar says:
QUERY = (columnname scott.test: "where between 5 May 12 02:57:00.000 h ' and ' 6 May 12 AM 02:59:59.999'")Who will fail in databases, because you assume nls_date_format. How it is difficult to put to_date() surround channels? Rather than play with quotation marks, using one parfile thusly.
query=table_owner.table_1:"where business_date between to_date('20120505025700 am','yyyymmddhhmiss am') and to_date('20120505025959 am','yyyymmddhhmiss am')" query=table_owner.table_2:"where business_date between to_date('20120505025700 am','yyyymmddhhmiss am') and to_date('20120505025959 am','yyyymmddhhmiss am')" query=table_owner.table_3:"where business_date between to_date('20120505025700 am','yyyymmddhhmiss am') and to_date('20120505025959 am','yyyymmddhhmiss am')"
You do not have to have all the clauses in a single line, as they are side by side parfile, which would be enough. For this reason parfile is better than the command line in order to avoid all the back-citing dance.
-
Name ID Startdate Enddate
AMIT a 1st October 09 3 October 09
AMIT a 3 October 09 5 October 09
AMIT B 5 October 09
BANU C 1st October 09 3 October 09
BANU D 3 October 09
CAREN E 1st October 09 2 October 09
CAREN F 2 October 09 5 October 09
CAREN E 5 October 09
Required result
Name ID Date
AMIT 5 October 09
AMIT B
BANU C 3 October 09
BANU D
CAREN E 2 October 09
CAREN F 5 October 09
CAREN E
My required result is I should list the names that changed the ids.for for example if amit is having has as ID in the third row the name should not be displayed in the result itself because amit is having the same ID.
How to query for this scenario?
-
How can I write the SQL query for this requirement?
Hello
I have a table that looks like this:
NAME | ANNUAL | VALUE
==== | ====== | =====
execno | 480. 000004
step | 480. 0400
SCNA | 480. cd_demo
System | 480. D47-010
type | 480. step
free_text | 480. stage 400
rbare | 480. RBA-1
execno | 482. 000004
SCNA | 482. cd_demo
System | 482. D47-010
free_text | 482. step 300
step | 482. 0300
type | 482. step
rbare | 482. RBA-1
execno | 483. 000001
type | 483. step
rbare | 483. rke1
SCNA | 483. rke10
step | 483. 0240
Now, say that I want to fetch ONLY annual with execno = '000004' and '400' = step and scna = "cd_demo" and system = "d47-010' and type = 'step', how to write SQL code?
At first, it seemed like a simple writing query but I've been struggling with it for hours without success. I must admit though that I'm not strong in SQL :-)
There, can anyone help? Please...
Thanks in advance.
Emmanuel
Published by: user12138559 on October 30, 2009 03:05Hi, Emmanuel.
Welcome to the forum!
Here's a way to do what you asked:
SELECT doc_id FROM table_x GROUP BY doc_id HAVING SUM (CASE WHEN name = 'execno' AND value = '000004' THEN 1 END) > 0 AND SUM (CASE WHEN name = 'step' AND value = '400' THEN 1 END) > 0 AND SUM (CASE WHEN name = 'scna' AND value = 'cd_demo' THEN 1 END) > 0 AND SUM (CASE WHEN name = 'system' AND value = 'd47-010' THEN 1 END) > 0 AND SUM (CASE WHEN name = 'type' AND value = 'step' THEN 1 END) > 0 ;
If you think that a WHERE clause would be used, but WHERE does apply to a single line. You need a condition that checks several rows in the same group.
WHEN has an effect something like WHERE.Published by: Frank Kulash, October 30, 2009 06:26
This solution assumes that (name, annual) is unique.
-
How to make the simple query for this scenario... ?
Hello:
Dummy table provided for simplicity.
It's my database table (Table_A)
Date1 | Plane1 | Category | Duration | Fees
01/01/2011 | A | Gold | 5. 2
01/01/2011 | C | Money | 4. 11
01/01/2011 | B | Gold | 6. 2
01/01/2011 | D | Gold | 2. 4
01/01/2011 | B | Gold | 3. 5
01/01/2011 | A | Money | 4. 8
01/01/2011 | B | Gold | 1. 3
I need to write a query to get the result below:
Date1 | Plane1 | Sum_Duration | Sum_Charge | Sum_Gold_Duration | Sum_Gold_Charge | Sum_Silver_Duration | Sum_Silver_Charge
01/01/2011 | A | 9. 10. 5. 2. 4. 8
01/01/2011 | B | 10. 10. 10. 10. 0 | 0
01/01/2011 | C | 4. 11. 0 | 0 | 4. 11
01/01/2011 | D | 2. 4. 2. 4. 0 | 0
This query will provide the 1st four columns:
SELECT Date1,
base1,
Sum (Duration) Sum_Duration,
Sum (load) Sum_Charge
FROM TABLE_A
GROUP BY date1, rarateplan
But I need to know how to get the rest of the columns (i.e. Summary according to categories; from 5 to 8 columns)? Is this can be done in a single query without writing subqueries?
Please let me know, (with code), the best way.
Thank you-
TanvirUse like this:
SELECT Date1,
base1,
Sum (Duration) Sum_Duration,
Sum (load) Sum_Charge,
SUM (decode(Category,'Gold',duration,0)) Sum_Gold_Duration,
SUM (decode(Category,'Gold',charge,0)) Sum_Gold_charge,
SUM (decode(Category,'Silver',duration,0)) Sum_Silver_Duration,
SUM (decode(Category,'Silver',charge,0)) Sum_Silver_charge
FROM TABLE_A
GROUP BY date1, rarateplanPublished by: SANT007 on August 11, 2011 11:04
-
Please keep in mind that I am a newbie. For the moment, I don't know how to write code, so I use Muse to try to build a Web site that is not super fancy writing know, then improve or build or create a new site later. I called Adobe and they said someone in the forums may know how to write code and that he could help me. That said, if someone could answer my questions and help me somehow, I'd be really grateful.
1. How can I write code, what code should I write to
Text?
Color of the text?
Text size?
Text/Font Style
Text effects (such as fly in or fly out, bounce in and out bounce, spin in and spin out, fade in and fade out, etc)?
Direction of text effect?
Time that the effect occurs, if it is applied, initiated, comes in? example fly in or fade?
Time than the last.
After the effect stops, turns off? example: fly away or fade out?
2. how to enter the code Muse?
3. should I have a program to write the code?
4. is there a function I could use on my computer, such as Notepad, to write the code, copy and paste it into Muse?
5. What is the best book or books to learn how to write css, code and everything I need to do to be able to do the above and more?
6. is there anything else I need to know or do to be able to do these things with the text?
You can find more information on the style of your text (paragraphs, titles, etc. in some of the tutorials here: TUTORIALS |) Adobe Muse CC
You can also check out tutorials on this page for scrolling effects that can do some of the other effects you need. Without exactly knowing your use case it's hard to give specific advice.
Basically if it is not covered undressed under the text, scrolling Effects tutorials or in a third party widget already made, then you will need to create it yourself using CSS. You will need to use some sort of browser Firebug like developer tools in Firefox to find the ID of the element you want to add the CSS to write the CSS code and insert it into the head section of the page properties.
-
How to write a query to join and right join
Hello
With the help of 10 gr 2:
I have a scenario where generate us a report by joining a few tables.
same goes for ex:
Select col1, col2, col5, col10 col22...
from tableA, tableB.
where tableA.col1 = tableB.col1 etc.
I have a requirement where choose a flag in the front-end server must be a right join. so, if the flag is N, I need to return the data returned by the join; but, if the flag is there I need to make a right join and returns all the data corresponding to table A and table B, as well as the data in table B.
(I did mention only two tables, as they are, they main engines, there are very many other tables joined in this request)
It is possible to write a query, so that the two scenarios can be addressed based on the flag?
Thanks in advance
Hello
user565033 wrote:
... When Oracle treats of the WHERE clause that starts from the bottom or the top? So it's best to put filters that reject the unnecessary lines at the beginning of the place where clause or end? Is how important it? ...
No, it does not matter.
The optimizer evaluates what condition will be faster and/or more selective (that is, will eliminate the most lines) and make the first condition.
If the optimzer cannot decide on what terms will be faster or more selective, it can arbitrarily don't close at the end of the WHERE clause first, but, even if you already knew for sure, this is exactly the kind of thing that is likely to change from one version to the other, or platform to another.
The optimizer (in recent versions, at least) is very good. If the optimizer can not say what conditions should apply first, then, chances are, there is really no significant difference, so it would be not serious of which one was made first.
If you read something that indicates the order is important, it is very outdated. Long ago (version 6), there was no cost-based optimizer and the order of the conditions in the WHERE clause was important. The cost-based optimizer was introduced in Oracle 7 (1992) and has been greatly improved by Oracle 8.1 (1998). Also later Oracle 10, the older optimizer ("regulated") was available for those who really want to continue to use it.
Maybe you are looking for
-
I can't print from any Web page, including my hotmail account, without printing the page to about 20% of the normal size. If I use Explorer, I have no problem with printing.
-
Cannot find or install android applications
I just bought a special edition Slate yesterday. But when I try to load applications, there is no aps android on it and I can't seem to register the device. It shows my old tablet when I enter via browser and mu apps for it, but I can not install any
-
What drivers need to be reinstalled (or removed) to reactivate the internal keyboard on an Aspire V5-551? The original keyboard driver where accidentally deleted. I already reinstalled the driver Dritek RF button (Radio controller).Except for the in
-
UM driver para o windous vista preciso instalar webcam 3.5
OS drivers than good com webcam 3.5 nao dao no meu pc. preciso UM windows vista in a couple o
-
How to measure the amount of traffic?
Hello ^ ^ In fact the question what I say, it's different from other issues that people are making inquires. However, I want to know my question because there is no one who can teach me... Old time, I was wondering how to measure traffic In other wor