Row value needs to be changes as column through SQL Query
HI ALL
I have a table like below
ID Month VALUES
1 01-jan 10
1 01-feb 20
2 01-jan 10
2 01-feb 20
I need the output like below
ID 01-jan 01-feb
1 10 20
2 10 20
How can i get it through SQL Query?. Please help me on that i have urgent work like this
In effect because you are wanting to take X rows and squish them down to 1 row per id, you are gouping on the ID to typically a group by clause is the best way to do this.
If you really wanted to do it without aggregate functions and a group by clause you would be looking for something like this...
SQL> ed
Wrote file afiedt.buf
1 WITH t as (select 1 as id, '01-jan' as month, 10 as val from dual union all
2 select 1, '01-feb', 20 from dual union all
3 select 1, '01-mar', 30 from dual union all
4 select 2, '01-jan', 10 from dual union all
5 select 2, '01-feb', 30 from dual union all
6 select 2, '01-mar', 60 from dual)
7 --
8 select id, jan, feb, mar
9 from (
10 select id
11 ,row_number() over (partition by id order by to_date(month,'dd-mon')) as rn
12 ,val as jan
13 ,lead(val) over (partition by id order by to_date(month,'dd-mon')) as feb
14 ,lead(val,2) over (partition by id order by to_date(month,'dd-mon')) as mar
15 from t
16 )
17* where rn = 1
SQL> /
ID JAN FEB MAR
1 10 20 30
2 10 30 60
SQL>Although this will only work if you can guarantee that there is a '01-jan' value for each id. If there could be missing values then you'll have to use aggregate functionality.
Similar Messages
-
Urgent= How to Group selected columns in sql query
Hi,
I need some urgent help on the following sql query. I 'm sure there is an easy way to do this but I'm stacked!Any help will be much appreciated!!
I have a query to retrieve the following columns:
I want the first 9 columns to be grouped together (not to be repeated) for any occurence of the last 3 columns (abs.ABSENCE_START_DATE,abs.ABSENCE_END_DATE, abs.DAYS_TAKEN DAYS_TAKEN_analysis)
SELECT DISTINCT
sum.employee_number ,
sum.EMPLOYEE_NAME,
sum.EMAIL_ADDRESS,
sum.ORGANIZATION ,
sum.BCEBF ,
sum.ALDE ,
sum.CURYRREMDAYS ,
sum.DAYS_TAKEN ,
sum.REMBCE ,
abs.ABSENCE_START_DATE
abs.ABSENCE_END_DATE,
abs.DAYS_TAKEN DAYS_TAKEN_analysis
--TO_CHAR(TO_CHAR(abs.ABSENCE_START_DATE)||' '||TO_CHAR(abs.ABSENCE_END_DATE)||' '||TO_CHAR(abs.DAYS_TAKEN)) DAYS_TAKEN_ANAL
FROM
HB_V_ANNUAL_LEAVE_SUMMARY_REP SUM,
HB_V_AN_LEAV_DAYS_TAKEN_REP ABS
WHERE
sum.employee_number = abs.EMPLOYEE_NUMBER
ORDER BY
sum.employee_number ,
sum.EMPLOYEE_NAME,
sum.EMAIL_ADDRESS,
sum.ORGANIZATION ,
sum.BCEBF ,
sum.ALDE ,
sum.CURYRREMDAYS ,
sum.DAYS_TAKEN ,
sum.REMBCE
Any feedback/help on how to do this will be highly appreciated.
Thanks a lot
ElenaPlease help!!
I used the break command to group columns that I do not want to repeat in my query output. When I run the query without formatting is working. But when I put all formatting to produce the required output I dont get the result I want.
Below is the exact sql query I use:
<<
SET TERMOUT OFF
SET ECHO OFF
SET ARRAY 35
SET HEA OFF
SET FEEDBACK OFF
SET PAGES 2000
col beginLINE format A100
col winsecidLINE format A100
col placeLINE format A100
COL LINEempty1 format A100
COL LINEempty2 format A100
COL LINEempty3 format A100
COL LINEempty4 format A100
COL LINEempty5 format A100
COL LINEempty6 format A100
COL LINEempty7 format A100
COL LINEempty8 format A100
COL LINEempty9 format A100
COL LINEempty10 format A100
col LINECOLempty format A100
col receiverLINE FORMAT A100
COL EMP_EMAIL_ADDRESS FORMAT A100
COL LINEHEADER FORMAT A100
COL unitsLINE FORMAT A100
COL lmLINE FORMAT A100
COL INTITLE FORMAT A100
COL LINECOL1 FORMAT A100
COL CIF FORMAT A100
COL EMPLOYEE_NAME FORMAT A100
COL ORGANIZATION FORMAT A100
COL LINECOL2 FORMAT A100
COL ALHEADER FORMAT A100
col LINECOL3 FORMAT A100
col BCEBF FORMAT A100
col ALDE FORMAT A100
COL CURYRREMDAYS FORMAT A100
COL DAYS_TAKEN FORMAT A100
col LINECOL4 FORMAT A100
COL REMBCE FORMAT A100
col LINECOL5 FORMAT A100
col LINECOL6 FORMAT A100
col ALHEADER2 FORMAT A100
col LINECOL7 FORMAT A100
col endLINE FORMAT A100
break on beginLINE on winsecidLINE on placeLINE on LINEempty1 ON LINEempty2 ON LINEempty3 ON LINEempty4 ON LINEempty5 ON LINEempty6 ON LINEempty7 ON LINEempty8 ON LINEempty9 ON LINEempty10 on receiverLINE on EMP_EMAIL_ADDRESS on LINEHEADER on unitsLINE on lmLINE on INTITLE on LINECOL1 on CIF on EMPLOYEE_NAME on ORGANIZATION on LINECOL2 on ALHEADER on LINECOL3 on BCEBF on ALDE on CURYRREMDAYS on DAYS_TAKEN on LINECOL4 on REMBCE on LINECOL5 on LINECOL6 on ALHEADER2 on LINECOL7 ON LINEempty11 ON endREPORT on endLINE
SPOOL C:\FORMATout.txt
SELECT
'{{begin}} '||chr(10) beginLINE,
'{{winsecid 999999}} '||chr(10) winsecidLINE,
'{{place rbsemail.tif 0 0}} '||chr(10) placeLINE,
' '||chr(10) LINEempty1,
' '||chr(10) LINEempty2,
' '||chr(10) LINEempty3,
' '||chr(10) LINEempty4,
' '||chr(10) LINEempty5,
' '||chr(10) LINEempty6,
' '||chr(10) LINEempty7,
' '||chr(10) LINEempty8,
' '||chr(10) LINEempty9,
' '||chr(10) LINEempty10,
'{{from [email protected]}} '||chr(10) receiverLINE,
'{{fax '|| EMAIL_ADDRESS||' }} '||chr(10) EMP_EMAIL_ADDRESS,
'{{Subject Annual Leave Summary Report as at '||sysdate||' }} '||chr(10) LINEHEADER,
'{{units cm}} '||chr(10) unitsLINE,
'{{lm 2.0}} '||chr(10) lmLINE,
'ANNUAL LEAVE SUMMARY REPORT AS AT '||sysdate INTITLE,
'---------------------------------------------------------------------' LINECOL1,
'CIF: '||CIF CIF,
'EMPLOYEE NAME: '||EMPLOYEE_NAME EMPLOYEE_NAME,
'DEPARTMENT DETAILS: '||ORGANIZATION ORGANIZATION,
'---------------------------------------------------------------------' LINECOL2,
'ANNUAL LEAVE DETAILS:' ALHEADER,
'---------------------------------------------------------------------' LINECOL3,
'BALANCE B/F FROM PREVIOUS YEAR: '||BCEBF BCEBF,
'DAYS ENTITLED FOR THE CURRENT YEAR: '||ALDE ALDE,
'CURRENT YEAR REMAINING DAYS: '||CURYRREMDAYS CURYRREMDAYS,
'DAYS TAKEN FOR THE CURRENT YEAR: '||DAYS_TAKEN DAYS_TAKEN,
'---------------------------------------------------------------------' LINECOL4,
'REMAINING BALANCE: '||REMBCE REMBCE,
'---------------------------------------------------------------------' LINECOL5,
'---------------------------------------------------------------------' LINECOL6,
'ANNUAL LEAVE DAYS TAKEN ANALYSIS FOR THE CURRENT YEAR:' ALHEADER2,
'---------------------------------------------------------------------' LINECOL7,
TO_CHAR('START DATE: '||ABSENCE_START_DATE||' '||'END DATE: '||ABSENCE_END_DATE||' '||'DAYS TAKEN : '||DAYS_TAKEN_ANAL) AL_DAYS_ANAL,
' '||chr(10) LINEempty11,
'-- End of Report -- '||chr(10) endREPORT,
'{{end}} '||chr(10) endLINE
FROM HB_V_AN_LEAV_SUM_DAYSTAKEN_REP
WHERE CIF IN ('098033','098024')
ORDER BY
beginLINE ,
winsecidLINE,
placeLINE ,
LINEempty1,
LINEempty2,
LINEempty3,
LINEempty4,
LINEempty5,
LINEempty6,
LINEempty7,
LINEempty8,
LINEempty9,
LINEempty10,
receiverLINE,
EMP_EMAIL_ADDRESS,
LINEHEADER ,
unitsLINE ,
lmLINE ,
INTITLE ,
LINECOL1,
CIF ,
EMPLOYEE_NAME ,
ORGANIZATION ,
LINECOL2 ,
ALHEADER ,
LINECOL3,
BCEBF ,
ALDE ,
CURYRREMDAYS ,
DAYS_TAKEN ,
LINECOL4 ,
REMBCE ,
LINECOL5 ,
LINECOL6 ,
ALHEADER2 ,
LINECOL7 ,
LINEempty11,
endREPORT,
endLINE
spool off
>>
The required output I want to get is:
<<
{{begin}}
{{winsecid 750612}}
{{place rbsemail.tif 0 0}}
{{from [email protected]}}
{{fax [email protected] }}
{{Subject Annual Leave Summary Report as at 04-APR-08 }}
{{units cm}}
{{lm 2.0}}
ANNUAL LEAVE SUMMARY REPORT AS AT 04-APR-08
CIF: 098024
EMPLOYEE NAME: Christou Christos Panteli
DEPARTMENT DETAILS: 003-031-010-314-03140-Special Projects
ANNUAL LEAVE DETAILS:
BALANCE B/F FROM PREVIOUS YEAR: 9
DAYS ENTITLED FOR THE CURRENT YEAR: 27
CURRENT YEAR REMAINING DAYS: 24
DAYS TAKEN FOR THE CURRENT YEAR: -3
REMAINING BALANCE: 33
ANNUAL LEAVE DAYS TAKEN ANALYSIS FOR THE CURRENT YEAR:
START DATE: 04-JAN-08 END DATE: 04-JAN-08 DAYS TAKEN : 1
START DATE: 24-JAN-08 END DATE: 24-JAN-08 DAYS TAKEN : 1
START DATE: 20-FEB-08 END DATE: 20-FEB-08 DAYS TAKEN : 1
-- End of Report --
{{end}}
{{begin}}
{{winsecid 750612}}
{{place rbsemail.tif 0 0}}
{{from [email protected]}}
{{fax [email protected]}}
{{Subject Annual Leave Summary Report as at 04-APR-08 }}
{{units cm}}
{{lm 2.0}}
ANNUAL LEAVE SUMMARY REPORT AS AT 04-APR-08
CIF: 098033
EMPLOYEE NAME: Demetriou Elena Steliou
DEPARTMENT DETAILS: 003-031-010-314-03140-Special Projects
ANNUAL LEAVE DETAILS:
BALANCE B/F FROM PREVIOUS YEAR: 15
DAYS ENTITLED FOR THE CURRENT YEAR: 27
CURRENT YEAR REMAINING DAYS: 25
DAYS TAKEN FOR THE CURRENT YEAR: -2
REMAINING BALANCE: 40
ANNUAL LEAVE DAYS TAKEN ANALYSIS FOR THE CURRENT YEAR:
START DATE: 15-JAN-08 END DATE: 15-JAN-08 DAYS TAKEN : 1
START DATE: 24-MAR-08 END DATE: 24-MAR-08 DAYS TAKEN : 1
-- End of Report --
{{end}}
>>
However the actual output we get from the above query is as follows:
<<
{{begin}}
{{winsecid 750612}}
{{place rbsemail.tif 0 0}}
{{from [email protected]}}
{{fax [email protected] }}
{{Subject Annual Leave Summary Report as at 04-APR-08 }}
{{units cm}}
{{lm 2.0}}
ANNUAL LEAVE SUMMARY REPORT AS AT 04-APR-08
CIF: 098024
EMPLOYEE NAME: Christou Christos Panteli
DEPARTMENT DETAILS: 003-031-010-314-03140-Special Projects
ANNUAL LEAVE DETAILS:
BALANCE B/F FROM PREVIOUS YEAR: 9
DAYS ENTITLED FOR THE CURRENT YEAR: 27
CURRENT YEAR REMAINING DAYS: 24
DAYS TAKEN FOR THE CURRENT YEAR: -3
REMAINING BALANCE: 33
ANNUAL LEAVE DAYS TAKEN ANALYSIS FOR THE CURRENT YEAR:
START DATE: 04-JAN-08 END DATE: 04-JAN-08 DAYS TAKEN : 1
-- End of Report --
{{end}}
START DATE: 24-JAN-08 END DATE: 24-JAN-08 DAYS TAKEN : 1
START DATE: 20-FEB-08 END DATE: 20-FEB-08 DAYS TAKEN : 1
{{fax [email protected] }}
{{Subject Annual Leave Summary Report as at 04-APR-08 }}
{{units cm}}
{{lm 2.0}}
ANNUAL LEAVE SUMMARY REPORT AS AT 04-APR-08
CIF: 098033
EMPLOYEE NAME: Demetriou Elena Steliou
DEPARTMENT DETAILS: 003-031-010-314-03140-Special Projects
ANNUAL LEAVE DETAILS:
BALANCE B/F FROM PREVIOUS YEAR: 15
DAYS ENTITLED FOR THE CURRENT YEAR: 27
CURRENT YEAR REMAINING DAYS: 25
DAYS TAKEN FOR THE CURRENT YEAR: -2
REMAINING BALANCE: 40
ANNUAL LEAVE DAYS TAKEN ANALYSIS FOR THE CURRENT YEAR:
START DATE: 15-JAN-08 END DATE: 15-JAN-08 DAYS TAKEN : 1
-- End of Report --
{{end}}
START DATE: 24-MAR-08 END DATE: 24-MAR-08 DAYS TAKEN : 1
>>
IF ANYONE CAN HELP ON THIS I WOULD REALLY APPRECIATE IT!
THANKS A LOT!
Best regards,
Elena -
Help needed in Exporting tables data through SQL query
Hi All,
I need to write a shell script(ksh) to take some of the tables data backup.
The tables list is not static, and those are selecting through dynamic sql
query.
Can any body tell help me how to write the export command to export tables
which are selected dynamically through SQL query.
I tried like this
exp ------ tables = query \" select empno from emp where ename\= \'SSS\' \"
but its throws the following error
EXP-00035: QUERY parameter valid only for table mode exports
Thanks in advance,Hi,
You can dynamically generate parameter file for export utility using shell script. This export parameter file can contain any table list you want every time. Then simply run the command
$ exp parfile=myfile.txt -
Need to pass the PROFILE options in SQL query
SELECT ffvs.FLEX_VALUE_SET_NAME
, ffvs.FLEX_VALUE_SET_ID
, ffv.FLEX_VALUE_ID
, ffv.FLEX_VALUE
FROM fnd_flex_value_sets ffvs
, fnd_flex_values ffv
WHERE 1=1
AND ffvs.FLEX_VALUE_SET_ID=ffv.FLEX_VALUE_SET_ID
AND ffvs.FLEX_VALUE_SET_ID=1012493 -- SCHEME_GL_OPTION
AND ffvs.FLEX_VALUE_SET_ID IN (select FLEX_VALUE_SET_ID from FND_FLEX_VALUE_RULE_LINES
where
FLEX_VALUE_RULE_ID
in
(select FLEX_VALUE_RULE_ID from FND_FLEX_VALUE_RULES where FLEX_VALUE_RULE_NAME='MDS ZA Option' ))
I am trying to to run the particular SQL qyery for creating the VIEW.
Concern:- It will pick all the columns of the values associated with all rules and GL account
--> I want to filter out by running the or using the PROFILE option so that it returns for only one RESP_ID.
Is it anyway to use in creating of view in the QUERY to pick the only one RESP_ID.
Hope I made clear my issue.My questions is to use this FND_PROFILE.VALUE('RESP_ID') or FND_PROFILE.VALUE('ORG_ID')
When ever you will run the above flex values query, it will come for all company or org id.
I want specific for one org for all the flex values when i will run the above query.
I try to initialize the query for the org_id,resp_id. But it returning for all of the org.
I have to filter out the values based on Org.Where as in the above query there is no org_id column for joing so how should i ?
Hope i make my questions right. -
Multiple cases based on Columns In SQL Query
There is a SQL query given below, that query performs DateDIff operation by selecting max and min date according to
TCard OR you can say id,
here' the query
SELECT
--COUNT(DIFF)
Count(DATEDIFF(D, MinDate, MaxDate)/30) AS DIFF
FROM (
SELECT
MAX(TDate) AS MaxDate,
MIN(TDate) AS MinDate
FROM EDATA
GROUP BY TCard
)a
Group by DATEDIFF(D, MinDate, MaxDate)/30
Now i want to apply some kind of sorting in this query before performing DateDiff operation (sorting can be based on several parameters
like age, name etc. but 1 at a time according to the cases)
Now I want to know How to apply cases over this query and where?You can apply sorting based on certain condition however you need to include those columns in your subquery. On custom sorting check out this article
here:
e.g.
SELECT CountryName
FROM dbo.Country
ORDER BY CASE WHEN
CountryName = 'INDIA' THEN '1'
WHEN CountryName = 'CHINA' THEN
'2'
ELSE CountryName END ASC
If this post answers your query, please click "Mark As Answer" or "Vote as Helpful". -
Need Help in Splitting a String Using SQL QUERY
Hi,
I need help in splitting a string using a SQL Query:
String IS:
AFTER PAINT.ACOUSTICAL.1..9'' MEMBRAIN'I would like to seperate this string into multiple lines using the delimeter .(dot)
Sample Output should look like:
SNO STRING
1 AFTER PAINT
2 ACOUSTICAL
3 1
4
5 9" MEMBRAIN
{code}
FYI i am using Oracle 9.2There's this as well:
with x as ( --generating sample data:
select 'AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN' str from dual union all
select 'BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN' str from dual)
select str,
row_number() over (partition by str order by rownum) s_no,
cast(dbms_xmlgen.convert(t.column_value.extract('//text()').getstringval(),1) as varchar2(100)) res
from x,
table(xmlsequence(xmltype('<x><x>' || replace(str,'.','</x><x>') || '</x></x>').extract('//x/*'))) t;
STR S_NO RES
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 1 AFTER PAINT
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 2 ACOUSTICAL
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 3 1
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 4
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 5 9" MEMBRAIN
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 1 BEFORE PAINT
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 2 ELECTRIC
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 3 2
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 4
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 5 45 caliber MEMBRAIN
{code} -
Need help with detail by hour in SQL query
Hello all,
I am using the following query to track the usage on a circuit and I have the detail by day, but now they are asking for hourly usage from 0900 to 1200 on these days. Any ideas how I can append to include hour in my detail?
select 'Report Name Here' as Circuit,'Usage' as Measurement,
MONTH(interfacetraffic.datetime) as month, year(interfacetraffic.datetime) as year, day(interfacetraffic.datetime) as day,
'' as Mo_yr,
interfaces.inbandwidth as bandwidth,
'' as adjustedbandwidth,
max (interfacetraffic.in_maxbps ) as max_in,
max (interfacetraffic.out_maxbps) as max_out,
avg(interfacetraffic.in_maxbps ) as avg_in,
avg(interfacetraffic.out_maxbps) as avg_out,
max(case (interfacetraffic.in_maxbps ) when 0 then 0 else(interfacetraffic.in_maxbps )/interfaces.inbandwidth *100 end) as 'max_in_%',
max(case ( interfacetraffic.out_maxbps) when 0 then 0 else( interfacetraffic.out_maxbps )/interfaces.outbandwidth *100 end) as 'max_out_%',
avg(case (interfacetraffic.in_maxbps ) when 0 then 0 else(interfacetraffic.in_maxbps )/interfaces.inbandwidth *100 end) as 'avg_in_%',
avg(case ( interfacetraffic.out_maxbps) when 0 then 0 else( interfacetraffic.out_maxbps )/interfaces.outbandwidth *100 end) as 'avg_out_%',
nodes.location as location,nodes.sysname as sysname,nodes.timezone,interfaces.interfaceid as interfaceid,nodes.nodeid as nodeid,interfaces.fullname as fullname
FROM
(Nodes INNER JOIN Interfaces ON (Nodes.NodeID = Interfaces.NodeID))
INNER JOIN InterfaceTraffic ON (Interfaces.InterfaceID = InterfaceTraffic.InterfaceID AND InterfaceTraffic.NodeID = Nodes.NodeID)
where InterfaceTraffic.DateTime > GETDATE() -180
and interfaces.InterfaceID = '31072'
and month(interfacetraffic.datetime) = 1
and year(interfacetraffic.datetime) = 2015
--and DATEPART(hh,interfacetraffic.datetime) in ('09','10','11','12','13','14','15','16','17','18','19')
group by interfaces.inbandwidth, year(interfacetraffic.datetime),
MONTH(interfacetraffic.datetime) ,nodes.location ,nodes.sysname,interfaces.inbandwidth,nodes.timezone ,interfaces.interfaceid,nodes.nodeid,interfaces.fullname, day(interfacetraffic.datetime)
--DAY(InterfaceTraffic.DateTime)select 'Report name here' as Circuit, 'Usage' as Measurement,
month(...) as month, year(...) as year, day(...) as day, datepart(hour, ...) as hour,
from ...
group by month(...), year(...), day(...), datepart(hour, ...), ...
Note - have you considered just having a single column for the date as opposed to 3 separate columns? And for efficiency, change your where clause from
where InterfaceTraffic.DateTime > GETDATE() -180
and interfaces.InterfaceID = '31072'
and month(interfacetraffic.datetime) = 1
and year(interfacetraffic.datetime) = 2015
to
where interfaces.InterfaceID = '31072'
and interfacetraffic.datetime >= '20150101' and interfacetraffic.datetime < '20150201'
and datepart(hour, ...) between 9 and 19
That first part involving "getdate() - 180" does nothing useful when you only want values from January of this year. -
Help on Aggregated Columns Through SQL
Hello All,
This is Sam, I am trying to pull the data from a table based on following criteria
1) Month To Date
2) Yesterday only
3) Whole Month
Below is the sql i created i could able to achieve SUM(NET_AMT) aggregated value for the Month To Date but could not able to figure out how i could create additional calculated columns for the other 2 criteria, could you please help me with the below query, the WITH clause i used is just to bring the total days in current month and current day number in the respective month, i think GROUP BY clause could not specified in CASE statement to aggregate based on dates, i am puzzled how to proceed further, appreciate your help, Thank you.
WITH X_DATE_H AS(
SELECT
PREV.DAY_DT AS PREV_DAY,
PREV.DAY_OF_MONTH AS CURR_DAY_MTD,
PREV.M_STRT_CAL_DT_WID AS MON_START_DAY_WID,
PREV.M_END_CAL_DT_WID AS MON_END_DAY_WID,
(PREV.M_END_CAL_DT_WID - PREV.M_STRT_CAL_DT_WID + 1) AS NO_DAYS_IN_MONTH
FROM W_DAY_D PREV, W_DAY_D CURR
WHERE CURR.DAY_DT = TRUNC(SYSDATE)
AND CURR.DAY_AGO_WID = PREV.ROW_WID
SELECT
SYSDATE AS SNAPSHOT_DATE,
TO_CHAR(SYSDATE,'YYYYMMDD') AS SNAPSHOT_DATE_WID,
PROD.PRODUCT_TYPE_CODE,
PROD.PRODUCT_TYPE_DESC,
X_DATE_H.CURR_DAY_MTD AS DAYS_MTD,
X_DATE_H.NO_DAYS_IN_MONTH AS DAYS_MONTH,
SUM(NET_AMT) AS BOOKING_AMT
FROM
X_DATE_H,
W_SALES_BOOKING_LINE_F BKG_F
LEFT JOIN W_PRODUCT_D PROD ON BKG_F.PRODUCT_WID=PROD.ROW_WID
LEFT OUTER JOIN W_INT_ORG_D ON (BKG_F.X_BRANCH_WID = W_INT_ORG_D.ROW_WID AND BKG_F.DATASOURCE_NUM_ID=W_INT_ORG_D.DATASOURCE_NUM_ID)
WHERE
BKG_F.X_MONTH_WID BETWEEN TO_CHAR(LAST_DAY(ADD_MONTHS(SYSDATE,-1))+1,'YYYYMMDD') AND TO_CHAR(SYSDATE,'YYYYMMDD')
GROUP BY SYSDATE, TO_CHAR(SYSDATE,'YYYYMMDD'), PROD.PRODUCT_TYPE_CODE,PROD.PRODUCT_TYPE_DESC,X_DATE_H.CURR_DAY_MTD,X_DATE_H.NO_DAYS_IN_MONTHHi, Sam,
Whenever you have a question, it helps to post:
(1) The version of Oracle (and any other relevant software) you're using
(2) A little sample data (just enough to show what the problem is) from all the relevant tables. You can probably post a good example with just 2 products and 3 dates.
(3) The results you want from that data
(4) Your best attempt so far (formatted) (You posted this, but since it's unformated, it's very hard to read.)
Executable SQL statements (like "CREATE TABLE AS ..." or "INSERT ..." statements) are best for (2).
Formatted tabular output is okay for (3). Type these 6 characters:
{code}
(small letters only, inside curly brackets) before and after formatted text, to preserve spacing.
Analytic functions are very good for doing things like running totals (such as month-to-date).
SYSDATE is constant with any query, even if the query takes a long time to run.
There's no point in grouping by a constant, so
GROUP BY SYSDATE
, TO_CHAR (SYSDATE,'YYYYMMDD')
, PROD.PRODUCT_TYPE_CODE
, ...produces the same results as
GROUP BY PROD.PRODUCT_TYPE_CODE
, ... -
Find a string between numeric in a column using SQL Query
Hi need help with the query in SQL. let say i have a column that has 2000 data.. i just need to show the data that has A at the strating of the data. For example:
A100001
W23456
A234444
I just need to show all the data got "A" at the start.
Thank uI don't think there is any standard command, so you will need to search for the pattern matching commands of your DBMS.
In SQL Server the keyword is "like", so your query would be Select col1 from tbl1 where col1 like 'A%'
Try to take over the world! -
During LTP material master values need to be modified
Hi ,
We are implementing LTP process in company. while LTP Run it pick the MRP1234 values for Simulative order creation. We have requirement to change the MRP1234 only during LTP run. Were as the MRP run will run with normal material master(MRP1234) values.
The values need to be changed are during LTP run are MRP group , Lox size etc., '''Thank you.. Almedia and köller..
We are already using this badi MD_MRP_PARAMETERS. We are facing the following problem
For example
header ATEST
component BCOMP
We need to switch off the bulk indicator and phantom for the component.
We are using the above bapi its manipulation only the header (ATEST) material master data but in LTP run during creation of header simulative planned. Component simulative dep requirement values are copied from material master. In this above bapi we are manipulating only header values.
When the next loop during component simulative planned order generation time the above parameters(bulk and phantom) are copied from component simulative dep requirement. Hence the switching of bulk indicator and phantom assembly is not working during ltp using this badi. This problem is happening for multi level components too.
Is there any suggestion for this issue.. -
Need help in SQL Query: Update a row in a table & insert the same row into another table
I want to update a row in a table say Table A and the updated row should be inserted into another table say Table B. I need to do it in a single SQL query and i don't want to do it in PL/SQL with triggers. And i tried with MERGE statement but its working with this scenario. (Note: I'm using Oracle Database 10g Enterprise Edition Release 10.2.0.1.0).
Thanks in Advance.Using Sven's code as an example, you could save the updated row in a sql plus variable. (also untested):
SQL> var v_id number
update tableA
set colB='ABC'
where colC='XYZ'
returning id into :v_id;
insert into table A_History (ID, colA, colB, ColC)
select id, ColA, ColB, ColC
from tableA
where id = :v_id; -
WHat is the best index type for non uniqueness / Varchar columns in SQL 2008 R2
Hello All Greetings,
Please help me here with my doubt,
in my table i have two columns about a million rows, it has about 20 columns in it, three columns with name as Period, Gender so most of the time these two columns use in where clause,
Gender will contain Either M or F , Period contains YYYY-Month (2013-December, 2013-August) etc so i would like to add a Index to these two columns so that in will increase the performance, so please let me know what type of indexes i need to add to
these columns in the table,
please note that only one time we will add data to the table which will take only 2 minutes but we query the table every day
so my question what is the best index type that i need to create on columns with non uniqueness values in the column.,
Thank you In Advance,
MilanThere is nothing whatever wrong with creating an index on a VARCHAR column, or set of columns.
Regarding the performance of VARCHAR/INT, as with everything in a RDBMS, it depends on what you are doing. What you may be thinking of is the fact that clustering a table on a VARCHAR key is (in SQL Server) marginally less efficient than clustering on a monotonically
increasing numerical key, and can introduce fragmentation.
Or you may be thinking of what you have heard about writing JOINs on VARCHAR columns - it is true, it is a little less efficient than a JOIN on numeric type, but it is only a little less efficient, nothing that would lead you to never join on varchar cols.
None of this does not mean that you should not create indexes on VARCHAR columns. A needed index on a VARCHAR column will boost query performance, often by orders of magnitude. If you need an index on a VARCHAR, create it. It makes no sense to try to find an
integer column to create the index on - the engine will never use it.
Check this reference: http://stackoverflow.com/questions/14041481/is-it-good-to-create-a-nonclustered-index-on-a-column-of-type-varchar
Mark ANSWER if this reply resolves your query, If helpful then VOTE HELPFUL
INSQLSERVER.COM
Mohammad Nizamuddin -
Retreving Hexadecimal Values from a table using SQL query.
Hi,
I'm looking for a query to retreive Hexadecimal values contained in a column using SQL query.
The column contains the values of all types, alphanumeric, numeric and hexadecimal.
I need to retreive only hexadecimal values.
any help to me in this regard will be appreciated.
ThanksPresumably, you can be sure that any valid hex value is indeed MEANT to BE a hex value. For example the value 'ACE' is meant to be a hexadecimal value and not the word.
-
SQL Query (updateable report) Region - Conditionally Hide and Set Values
SQL Query (updateable report) Region - Conditionally Hide and Set Values
Outline of requirement :-
Master / Detail page with Detail updated on same page using SQL Query (updateable report).
The detail region has the following source
SELECT item_id,
contract_id,
CASE WHEN hardware_id IS NOT NULL THEN
'HA'
WHEN backup_dev_id IS NOT NULL THEN
'BD'
WHEN hardware_os_id IS NOT NULL THEN
'HS'
END item_type,
hardware_id,
backup_dev_id,
hardware_os_id
FROM "#OWNER#".support_items
WHERE contract_id = :P26_CONTRACT_IDThe table support_items implements arced relationships and has the following columns
CREATE TABLE SUPPORT_ITEMS
ITEM_ID NUMBER NOT NULL,
CONTRACT_ID NUMBER NOT NULL,
HARDWARE_ID NUMBER,
BACKUP_DEV_ID NUMBER,
HARDWARE_OS_ID NUMBER
)A check type constaint on support_items ensures that only one of the fk's is present.
( hardware_id IS NOT NULL
AND backup_dev_id IS NULL
AND hardware_os_id IS NULL
OR ( hardware_id IS NULL
AND backup_dev_id IS NOT NULL
AND hardware_os_id IS NULL
OR ( hardware_id IS NULL
AND backup_dev_id IS NULL
AND hardware_os_id IS NOT NULL
) Hardware_Id is a FK to Hardware_Assets
Backup_dev_id is a FK to Backup_Devices
Hardware_os_id is a FK to Hardware_op_systems
The Tabular Form Element based on item_type column of SQL query is Displayed As Select List (based on LOV) referencing a named list of values which have the following properties
Display Value Return Value
Hardware Asset HA
Backup Device BD
Computer System HSThe Tabular Form Elements for the report attributes for hardware_id, backup_dev_id and hardware_os_id are all Displayed As Select List (Based on LOV).
What I want to do is only display the Select List for the FK depending on the value of the Select List on Item Type, e.g.
Item_Type is 'HA' then display Select List for hardware_id, do not display and set to NULL the Select Lists for backup_dev_id and hardware_os_id.
Item_Type is 'BB' then display Select List for backup_dev_id, do not display and set to NULL the Select Lists for hardware_id and hardware_os_id.
Item_Type is 'HS' then display Select List for hardware_os_id, do not display and set to NULL the Select Lists backup_dev_id and hardware_id.
There are properties on elements to conditionally display it but how do we reference the values of the SQL query Updateable region? they are not given a page item name?
Also on the Tabular For Elements there is an Edit tick against a report item - however when you go to the Column Attributes there is not a property with which you can control the Edit setting.
What's the best way of implementing this requirement in APEX 3.1?
Thanks.>
Welcome to the forum: please read the FAQ and forum sticky threads (if you haven't done so already), and update your profile with a real handle instead of "user13515136".
When you have a problem you'll get a faster, more effective response by including as much relevant information as possible upfront. This should include:
<li>Full APEX version
<li>Full DB/version/edition/host OS
<li>Web server architecture (EPG, OHS or APEX listener/host OS)
<li>Browser(s) and version(s) used
<li>Theme
<li>Template(s)
<li>Region/item type(s) (making particular distinction as to whether a "report" is a standard report, an interactive report, or in fact an "updateable report" (i.e. a tabular form)
With APEX we're also fortunate to have a great resource in apex.oracle.com where we can reproduce and share problems. Reproducing things there is the best way to troubleshoot most issues, especially those relating to layout and visual formatting. If you expect a detailed answer then it's appropriate for you to take on a significant part of the effort by getting as far as possible with an example of the problem on apex.oracle.com before asking for assistance with specific issues, which we can then see at first hand.
I have a multi-row region that displays values and allows entries in a number of fields.Provide exact details of how this has been implemented. (An example on apex.oracle.com is always a good way to do this.)
I should like the fields to be conditional in that they do not permit entry, but still display, if certain conditions apply (e.g. older rows greyed out). Can this be done? Almost anything can be done, often in multiple ways. Which are appropriate may be dependent on a particular implementation, the skills available to implement it, and the effort you're willing to expend on it. Hence it's necessary to provide full details of what you've done so far... -
How many columns a sql selects
I need to find out how many columns are in a sql statement like below:
sql = "select id, decode(description,'','No decription', description), comment from my_table";
The sql string is build dynamically so I don't know it when I write the code. I need to know before I do
call rs.next(), because I need to set up the table header so I need to know how many columns the sql is selecting.
Thanks inadvance.
BotaoYou can use the interface ResultSetMetaData,below are some methods of it.
int getColumnCount()
Returns the number of columns in this ResultSet object.
String getColumnName(int column)
Get the designated column's name.
int getColumnType(int column)
Retrieves the designated column's SQL type.
for more infomation ,you can refer to JDBC Online Document.
Maybe you are looking for
-
Change color in alv list header
hi experts, how can i change the color in a alv header... for example... number docum year 001 13245 2006 002 13245 2007 the header.. number, docum and year appears in light blue (all the cell) , how
-
Hi All, I am generating webservice in ID for an RFC and using this webservice in webdynpro application to get data from R/3 system.It is webservice to RFC synchronous scenario In RFC response structure data type of one field is "xstring" in R/3 syste
-
Can't open iPhoto library after upgrade
I upgraded iphoto after install OSX Mavericks recently but I can't open iphoto library with the newer version. (It says "Your photo library will not be readable by previous versions of iPhoto after the upgrade. The upgrade process for very large libr
-
Solution: iMac Address Book - Issues when Editing or Deleting Contacts
Is there a way to select a bunch of similarly posted questions and propose to "ALL" an answer or solution? Hardware & Version: I have the iMac OS X Lion 10.7.4 (as of this writing) Every so often, after updates, there seems to be rights issues with
-
How do I get page numbers on the left and right side of the page?
I am finishing up a book in PAGES '08 on my Mac. How do I get page numbers on the left and right side of the page. I can get them on the page but I'd like them on the left and right sides. Evan