IIf condition between dates using mdx query
Hi,
how to check IIF condition between dates using mdx query.
I able to check single year,plese check below mdx query.I need to check members between years.
my requirement is member is belongs to between years(2007 to 2010),display "yes" else "NO";
Could you please give me exact mdx query.
From,to-2007,2010,if member belongs to 2007to 2010 then disply "yes"else "no".
how to pass two members in IIf condition.
WITH
MEMBER Measures.[test]
AS Iif([Date].[Calendar Year].currentmember
is [Date].[Calendar Year].&[2007],"no","yes")
SELECT {Measures.[test]}
on 0
,[Product].[Subcategory].[Subcategory].MEMBERS * [Date].[Calendar Year].[Calendar Year]
ON 1
FROM [Adventure Works]
indu
Hi Sriindu,
consider the following:
WITH
MEMBER measures.[test] AS
IIF
Exists
[Date].[Calendar Year].CurrentMember
[Date].[Calendar Year].&[2007] : [Date].[Calendar Year].&[20010]
).Item(0)
IS
[Date].[Calendar Year].CurrentMember
,"yes"
,"no"
SELECT
{measures.[test]} ON 0
[Product].[Subcategory].[Subcategory].MEMBERS
[Date].[Calendar Year].[Calendar Year] ON 1
FROM [Adventure Works];
Philip,
Similar Messages
-
Using mdx query from Java Apache
Please suggest/guide me how to use MDX query to pull data from cube from Apache JAVA??
BI GUYHi BIGUY,
Multidimensional Expressions (MDX) is the query language that you use to work with and retrieve multidimensional data in Microsoft Analysis Services. MDX is based on the XML for Analysis (XMLA) specification, with specific extensions for SQL Server Analysis
Services.
According to your description, it's hard to give your the exact MDX query to pull the data which you want from the cube since there are no any detail information about the cube. Here are some basic knowledge for your reference.
Querying Multidimensional Data with MDX
MDX Sample
Regards,
Charlie Liao
TechNet Community Support -
Except function with parent child hierarchy using mdx query
HI,
I need to remove some items using mdx query in parent child hierarchy.
I tried with below query,it is not removeing ,could you please help me.
SELECT
{[Measures].[Amount]} ON
COLUMNS
NonEmpty([Account].[Accounts].[Account Level 01],[Measures].[Amount])
ON ROWS
FROM (SELECT
-Descendants({[Account].[Accounts].&[47]},,Leaves)
} ON COLUMNS
FROM [Adventure Works])
induHi Indu,
Why do you remove some itmes using
Descendants function? Generally, we use FILTER function to achieve the requirement.
WITH SET [CustomAccounts] AS
FILTER ([Account].[Accounts].[Account Level 01].Members , [Account].[Accounts].CurrentMember.Name<>'Net Income')
SELECT {[Measures].[Internet Sales Amount]} ON 0
[CustomAccounts] ON 1
FROM [Adventure Works]
WITH SET [CustomAccounts] AS
FILTER ([Account].[Accounts].[Account Level 01].Members , [Account].[Accounts].CurrentMember.Name='Net Income')
SET [RemainingAccount] AS
[Account].[Accounts].[Account Level 01]- [CustomAccounts]
SELECT {[Measures].[Reseller Sales Amount]} ON 0
[RemainingAccount] ON 1
FROM [Adventure Works]
Results.
References.
http://www.databasejournal.com/features/mssql/article.php/3306101/MDX-Essentials-Basic-Set-Functions-The-Filter-Function.htm
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/c0149678-97f2-4066-903f-7f9e9ff09b56/filtering-out-dimension-members-with-mdx?forum=sqlanalysisservices
Regards,
Charlie Liao
If you have any feedback on our support,
please click here.
Charlie Liao
TechNet Community Support -
Date parameters using MDX query
Hello experts,
Not sure if this question falls under SSAS or SSRS but I'm writing it here for now and hopefully get the answer.
I'm using SSAS cube to develop a report using SSRS and this is the first time I'm doing it. I want to filter records based on date range and did some research online. My report contains two datasets:
1. dsMain dataset -> it contains all the field which I want to use in the report and added a parameter thru query designed with following settings:
Dimension : Dates
Hierachary : Date
Operator : Range (Inclusive)
Parameters : checked
it created two parameters called FromDatesDate and toDatesDate
2. I created another dataset called dsDate and wrote a custom query (found at following link) and changed FromDatesDate and ToDatesDate using this date dataset
https://jsimonbi.wordpress.com/2011/03/22/using-a-date-parameter-in-ssrs-with-mdx/
Query for dsDate
WITH
MEMBER DateValue
AS
[Dates].[Date].CurrentMember.UniqueName
MEMBER DateLabel
AS
[Dates].[Date].CurrentMember.Name
SELECT
[Measures].[DateValue],
[Measures].[DateLabel]
} ON 0,
[Dates].[Date].[Date]
} ON 1
FROM [myCube]
Here is the value returned by dsDate dataset (above query)
DateValue DateLabel
06/04/1980 [Dates].[Date].&[29375]
06/04/1980
06/05/1980 [Dates].[Date].&[29376]
06/05/1980
06/06/1980 [Dates].[Date].&[29377]
06/06/1980
06/07/1980 [Dates].[Date].&[29378]
06/07/1980
06/08/1980 [Dates].[Date].&[29379]
06/08/1980
06/09/1980 [Dates].[Date].&[29380]
06/09/1980
06/10/1980 [Dates].[Date].&[29381]
06/10/1980
06/11/1980 [Dates].[Date].&[29382]
06/11/1980
06/12/1980 [Dates].[Date].&[29383]
06/12/1980
06/13/1980 [Dates].[Date].&[29384]
06/13/1980
Here is what I changed in FromDatesDate and ToDatesDate parmeter:
Under Available Values tab:
Dataset : dsDate
Value Field : DateValue
Label Field : DateLabel
Here are my questions:
1. I want to use date/time parameter so that user doesn't have to scroll thru whole date dimension.
2. I changed the FromDatesDate and ToDatesDate to date/time parameter, removed the values from Available values tab and made the following changes on Parmaeters expression under dsMain dataset
=”[Dates].[Date].&[” + Format(CDate(Parameters!FromDatesDate.Value),”MM/dd/yyyy”)
+ “T00:00:00]”
=”[Dates].[Date].&[” + Format(CDate(Parameters!ToDatesDate.Value),”MM/dd/yyyy”)
+ “T00:00:00]”
Now when I run the report I get following error:
Query (1, 55) The restrictions imposed by the CONSTRAINED flag in the STRTOMEMBER function are violated.
I think the reason is by changing parameter to date/time, now I cannot get "DateValue" which is required for the query.
1. What is the best way to work with date parameters?
Hope it is all clear and look forward to hear from experts.
Thanks,
P
mark it as answer if it answered your question :)Hi Parry2k,
In Analysis Services, a member can be referenced by either its member name or by its member key. The member key is used by the dimension to specifically identify a given member. The ampersand (&) character is used in MDX to differentiate
a member key from a member name. In this scenario, the datetime is member name, not the member key. So you should not add "&".
Reference:
Member Names and Keys
Simon Hou
TechNet Community Support -
How to get the child data in MDX query?
I have an MDX query that will return the data for an OLAP report. These report data include the parent_id, child_id and some dimensions data in it. How do I modify the MDX query to have a New member to show a dimension value of the child_id.
The child_is is actually the parent_id on another row. It is the "Pstpd Decision" I want to be included in a new column using the "Appeal Id". Thanks
WITH MEMBER [Measures].[Avg TA Time] AS [Measures].[Turn Around Time]/[Measures].[Number of Request]
SELECT NON EMPTY { [Measures].[Number of Request] } ON COLUMNS,
NON EMPTY { ([Request Date Time].[FY-AP].[Account Period].ALLMEMBERS *
[Request Drugs].[Drug Generic Name].[Drug Generic Name].ALLMEMBERS *
[Dispensary].[Dispensary Hierarchy].[Dispensary].ALLMEMBERS *
[Disease].[Tumour Group Site].[Tumour Group Site].ALLMEMBERS *
[Disease].[Tumour Group Sub Site].[Tumour Group Sub Site].ALLMEMBERS *
[Patient].[Patient Agency ID].[Patient Agency ID].ALLMEMBERS *
[Pstpd Decision].[Decision].[Decision].ALLMEMBERS *
[Request].[Request Id Key].[Request Id Key].ALLMEMBERS *
[Request].[Appeal Id].[Appeal Id].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
FROM ( SELECT ( { [Appeal Yes No].[Status].&[Yes] } ) ON COLUMNS
FROM ( SELECT ( STRTOSET(@RequestDateTimeFiscalYear, CONSTRAINED) ) ON COLUMNS
FROM [CAP Request])) WHERE ( IIF( STRTOSET(@RequestDateTimeFiscalYear, CONSTRAINED).Count = 1, STRTOSET(@RequestDateTimeFiscalYear, CONSTRAINED), [Request Date Time].[Fiscal Year].currentmember ), [Appeal Yes No].[Status].&[Yes] ) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
data.
KahluaI got it to work by adding the child_id's "decison' to the fact table as it is alot easier to get that data using Sql Script while creating the fact table and also there is already a "decsion" dimension setup. In the cube I can select the
parent_id's decision and/or child_id's decision. It is working on the report. Thanks.
Kahlua -
Hi,
I am new to mdx and struggling with the syntax.
I have made the below (simple) query wich works fine.
select {(EJV1, Dec, [RUBRIEK 5] )} on Columns,
Descendants([109]) on rows
From Resultat
where (FY10, Prognose, [geen klant], [Geen omzet])
Now i would like to have a year to date value.
When i use the query below i see all the separate months.
How can I adjust this query so the period values are aggregated?
select { (YTD([Dec]))} on Columns,
Descendants([109]) on rows
From Resultat
where (FY10, Prognose, [geen klant], [Geen omzet])
Thanks.We use a VALUE dimension to dynamically calculate YTD/QTD/Thousands/Millions...
Our ASO database has P&L and B/S data so this YTD Member Formula handles them differently:
IIF(IsLevel([TIME].Currentmember, 0),
IIF(IsAncestor([Balance_Sheet_Accounts ], [ACCOUNTS].Dimension.CurrentMember),
[TIME].CurrentMember,
Sum(PeriodsToDate ([TIME].Generations(2), [TIME].Currentmember))
0
This lets us query with Excel as if we had the Dynamic Time Series functionality of BSO.
Edited by: baboland on May 20, 2010 1:53 PM
Edited by: baboland on May 20, 2010 1:54 PM -
SSRS report using mdx query to display sales of product by yearwise
There is a requirement to create SSRS report as
Product +Calender2011 -Calender 2012 +Calender 2013
+ Calender 2014
Jan12 Feb12 Mar12...
Product 1 50 100 200 ..
Product 2 150 900 200 ..
Product 3 250 180 900 ..
Product 4 450 100 200 ..
Product 5 50 100 200 ..
Product 6 50 100 200 ..
When I click on Calender2011 corresponding all months of 2011 has to appear and likewise for Calender2012, CalenderN
The MDX query I have like as follows-
Select Non Empty{
[Measures].[Product1],
[Measures].[Product2],
[Measures].[Product3],
[Measures].[Product4],
[Measures].[Product5],
[Measures].[Product6],
[Measures].[Product7],
[Measures].[Product8],
[Measures].[Product9],
[Measures].[Product10],
[Measures].[Product11],
} ON Rows ,
Non Empty { ([Dim Calendar H].[Year Name].[Year Name] ) *([Dim Calendar H].[Month name].[Month name])
ON COLUMNS
FROM ( SELECT ( { [Dim Calendar H].[Year Name].&[Calendar 2014],
[Dim Calendar H].[Year Name].&[Calendar 2013],
[Dim Calendar H].[Year Name].&[Calendar 2012],
[Dim Calendar H].[Year Name].&[Calendar 2011] } )
ON COLUMNS
FROM [Cube])
Please help me.
Advance thanks...Hi Afans,
According to your description, you want to create a drill-down report using SQL Server Analysis Services database, right?
In this case, you need add the Year and Month fields to the column group, and set the Month column can be toogled by Year column group. I have teste it on my local environment, here is the sample query for your reference.
select [Measures].[Internet Sales Amount] on 0,
[Product].[Category].members*[Date].[Calendar].[Calendar Year].members*[Date].[Month of Year].members on 1
from
[Adventure Works]
Reference
http://popbi.wordpress.com/2012/03/02/ssrs-how-to-add-a-column-group-to-an-existing-table/
http://msdn.microsoft.com/en-IN/library/dd207042.aspx
Regards,
Charlie Liao
TechNet Community Support -
I have a MDX query that I want to use in the RPD as "Table Type" =Select
I did create a new object as "Physical Dimension" and gave the below script as Essbase 11 specific SQL, but this does not work and an getting the generic error "[nQSError: 15002] Missing navigation space for subject area test. (HY000)". Any Idea as to how to use the MDX in RPD?
MDX Script:
with set classes as '{[Class_Data],[Inventory_Class_Data]}'
set ledgers as '{[Actuals_Ledger],[Finance_Ledger],[Reclass_Ledger],[Allocation_Ledger],[Blending_Ledger],[HCSADJ_Ledger]}'
set bu as '{[UTHCS],[UTMBG],[CONSL]}'
set account as 'Except ({filter ([Accounts].Levels(0).members, IsAncestor([SRECNA],[Accounts].CurrentMember)),
filter ([Accounts].Levels(0).members, IsAncestor([MISC_AUDIT],[Accounts].CurrentMember)),
filter ([Accounts].Levels(0).members, IsAncestor([SNA],[Accounts].CurrentMember))},{[Change in Net Assets and Restatements]})'
set funds as '{filter ([Fund].Levels(0).members,IsAncestor([All_Funds],[Fund].CurrentMember)),
filter ([Fund].Levels(0).members,IsAncestor([Do Not Use Funds],[Fund].CurrentMember))}'
select {[Act]} on columns,
Non Empty (CrossJoin(CrossJoin(
CrossJoin(account,funds),
CrossJoin(ledgers,bu)
),classes)
) on rows
from [finrpt15.work]
where (FY15,YTD_Apr,UTMB_INSTITUTION);
Thanks,
RaviHi BIGUY,
Multidimensional Expressions (MDX) is the query language that you use to work with and retrieve multidimensional data in Microsoft Analysis Services. MDX is based on the XML for Analysis (XMLA) specification, with specific extensions for SQL Server Analysis
Services.
According to your description, it's hard to give your the exact MDX query to pull the data which you want from the cube since there are no any detail information about the cube. Here are some basic knowledge for your reference.
Querying Multidimensional Data with MDX
MDX Sample
Regards,
Charlie Liao
TechNet Community Support -
Failing to import data using SQL query
I am trying to import data from a sql query to analysis service in SSDT. i went to model > import from data source >Microsoft SQL Server and i chose from query. I typed my query which works fin in SSMS and when i press import if gives me a error. what
is going on please help here is the error
DirectQuery error: All tables used when querying in DirectQuery Mode must be from a single relational Data Source.
here is my query:
USE AdventureWorks2012;
SELECT SalesPersonID, [29484] Brian, [29485] Peter, [29486] Frank, [29518] Sarah, [29519] Janet, [29520] Alice, [29608] Martin, [29609] Patrick, [29610] Wasu, [29780] Samanyika, [29781] Vladmire
FROM
SELECT SalesOrderID, SalesPersonID, CustomerID
FROM Sales.SalesOrderHeader
WHERE SalesPersonID IS NOT NULL
As P PIVOT
COUNT (SalesOrderID) FOR CustomerID IN ([29484], [29485], [29486], [29518], [29519], [29520], [29608], [29609], [29610], [29780], [29781])
AS PVT
ORDER BY SalesPersonID ASC;Hi,
When importing data from relational data source, the steps are:
In SQL Server Data Tools (SSDT), click the Model menu, and then click Import
from Data Source.
On the Connect to a Data Source page, select the type of database to connect to, and then click Next.
Follow the steps in the Table Import Wizard. On subsequent pages, you will be able to select specific tables and views or apply filters by using the Select
Tables and Views page or by creating a SQL query on Specify a SQL Query page.
As we can see on the steps, we need to select one database, so we needn't to write "USE AdventureWorks2012" on the query.
Reference:Import from a Relational Data Source
Regards,
Charlie Liao
TechNet Community Support -
Order mismatch in selected data using Select query
Hello Experts,
We are upgrading from 4.6C to ECC6. I came across a select query on a custom table, which gives different order of data from 4.6C to ECC6. Data (no. of records) is same in both the servers but order is different. Table doesn't have indexes in either 4.6C or ECC6. What would be the cause for order change?
Further, in 4,6C, ECC6 and data bases order of the data is totally different. Select query have some conditions in where clause with select options, but in both the cases (4.6C and ECC6) I am not passing any data from the selection screen so am getting entire data from the data base.
Thanks in advance
PhalaniFrom the SAP service market place I found that
1. Unless we use SORT or ORDER BY clause the order of the data is not in our control.
2. In 4.6C, two same select queries never give the result in the same order, if the primary key contains character fields.
Thanks for your help.
Phalani -
Filtering data using sql query
I am pulling data from a database which is a log of events type data. It consists of entries at a certain time, entry text, and even has an entry type. One of those types is known as "open item." This entry has the potential to be present on multiple days over and over. The problem is I only want the "open item" entries to appear that occur on the most recent day of a date range that is input by the user, but also not excluding all other entries from all of the other days that are not "open item." The "is_open=0" is what is excluding the "open items" from all of the entries, but now there needs to be a way to include (ie. "is_open=1") the "open items" on the current day. My query is as follows:
SELECT b.log_title, a.log_id, MIN(a.shift_date) AS shift_date,a.shift_id,a.operator_position_descr,a.is_open,a.user_id, MAX(a.annotation_number) AS annotation_number,
a.entry_text, MIN(a.entry_time) AS entry_time,a.font_num
FROM log_entries AS a INNER JOIN
log_list AS b ON a.log_id = b.log_id
WHERE ((entry_type_code NOT LIKE '%NLOG%'
AND entry_type_code <> 'daily'
AND entry_type_code <> 'shift act') or entry_type_code is null)
AND (is_open = 0 AND is_standing_order = 0 AND is_rolled_forward is null)
GROUP BY b.log_title, a.log_id, a.user_id,a.shift_id,a.operator_position_descr,a.is_open, a.entry_text,a.font_num
Order by entry_timeChange you WHERE clause to something like this... (You didn't say what kind of DB you were using so I used SQL Server syntax)
WHERE ((entry_type_code NOT LIKE '%NLOG%'
AND entry_type_code IN ('daily', 'shift act')) OR entry_type_code is null)
AND (is_open = 0 OR (is_open = 1 AND a.shift_date >= DateAdd(dd, DateDiff(dd, 0, GetDate()), 0)))
AND is_standing_order = 0
AND is_rolled_forward is null
The biggest change is this... AND (is_open = 0 OR (is_open = 1 AND a.shift_date >= DateAdd(dd, DateDiff(dd, 0, GetDate()), 0))).
It allows is_open = 1 if the shift_date is => midnight of the of the current day.
HTH,
Jason -
Master Data Deletion - Data used in query
Hi all,
I work with BI 7. I noticed a strange thing. I wanted to delete data from a master data object, but the operation is not allowed. If I see the logs for "where used list", I see a query. I deleted data from DSO objects and infocubes, and I thought it was enough.
Any idea?
Thanks a lot.Hello Gianluca,
To be able to delete master data, no transaction data must exist for this master data, the master data must no longer be used as attribute value, hierarchies to this master data must not exist, and it must not be used in a query.
If you look at a record in the SID table, you can check the usage flag DATAFL. If the value is X, it is used or has been used by another BW oject.
But to answer your question, do delete the master data, it must no longer be used in a query.
Best Regards,
Vincent -
How to get AD reconciliation event data using SQL query.
Hi All,
I was trying to get all recon data for Target AD Recon from OIM db, but it seems that in OIM 11g we do not have recon data in tables: RCU, RCE, etc. We have to use "RECON_..." tables, my question is does any bady has sample query to fetch data from recon tables?
best
mpIt should be a question of linking your AD user reconciliation table (beginning RA_) with the RECON_EVENTS table by RE_KEY.
In my case I have OID user reconciliation (so my RA_ table will be different to yours) and can use something like:
SELECT RECON_EVENTS.RE_STATUS, RA_OIDUSER5.* FROM RECON_EVENTS, RA_OIDUSER5 WHERE RECON_EVENTS.RE_KEY = RA_OIDUSER5.RE_KEY;
Obviously it then depends on what information you want to filter on and retrieve. -
Can we have a if condition during data selection in Query Report (SQ02)
Hi all,
I have a required where in need to create a query report , where in which there are two types of condition exists.
first i input either functional location into View V_EQUI , when there is a equipment BOM exists(or when there is any entry for Equipment feild exists ) then the selected euipment should be passed to EQST else if equipment doesnot exist then the Functional location should be passed to TPST.
Now that I created a query report with base table as V_EQUI and joined it with EQST and whenever the equipment feild has a entry , it passes the equipment to EQST and works fine.
Now for some Functional location there is no equipment feild that exists for these base table is V_EQUI now when there is no entry for equipment , the functional location should be passed to TPST.
Now I would I achieve that.
Can I put a if condition to check on if equipment is initial then select X Y Z from tpst where fl = v_equi-fl.
Regards,
Rajx
-
Help needed in inserting data using a query
I need to have some data as a result of the following query:
select sched_num,load_id,ord_id,split_id from ord_load_seq
where (ord_id,split_id,sched_num) in (select ord_id,split_id,sched_num from ord_load_seq where seq_num = '2'
group by ord_id,split_id,sched_num having count(1) >1)
order by ord_id,split_id,sched_num;
But currently it retunrns no rows. The problem is in the having count(1)> 1 clause.
When i make =1, it returns rows. But no rows on > 1. I even tried inserting some rows to get the result >1
But still the query on a whole returns no rows.Please help.ohhh... lets start our lesson children:
here is code to consider:
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.2.0
SQL>
SQL> --Q1
SQL> with tbl as
2 (select 1 fld1, 1 fld2, 1 fld3 from dual
3 union all
4 select 1 fld1, 1 fld2, 2 fld3 from dual
5 union all
6 select 1 fld1, 1 fld2, 3 fld3 from dual
7 union all
8 select 1 fld1, 2 fld2, 3 fld3 from dual
9 union all
10 select 1 fld1, 3 fld2, 3 fld3 from dual)
11 select fld1, fld2, fld3 from tbl
12 order by fld1, fld2, fld3
13 /
FLD1 FLD2 FLD3
1 1 1
1 1 2
1 1 3
1 2 3
1 3 3
SQL> --Q2
SQL> with tbl as
2 (select 1 fld1, 1 fld2, 1 fld3 from dual
3 union all
4 select 1 fld1, 1 fld2, 2 fld3 from dual
5 union all
6 select 1 fld1, 1 fld2, 3 fld3 from dual
7 union all
8 select 1 fld1, 2 fld2, 3 fld3 from dual
9 union all
10 select 1 fld1, 3 fld2, 3 fld3 from dual)
11 select fld1, fld2, fld3, count(1) from tbl
12 group by fld1,fld2,fld3
13 order by fld1, fld2, fld3
14 /
FLD1 FLD2 FLD3 COUNT(1)
1 1 1 1
1 1 2 1
1 1 3 1
1 2 3 1
1 3 3 1
SQL> --Q3
SQL> with tbl as
2 (select 1 fld1, 1 fld2, 1 fld3 from dual
3 union all
4 select 1 fld1, 1 fld2, 2 fld3 from dual
5 union all
6 select 1 fld1, 1 fld2, 3 fld3 from dual
7 union all
8 select 1 fld1, 2 fld2, 3 fld3 from dual
9 union all
10 select 1 fld1, 3 fld2, 3 fld3 from dual)
11 select fld1, fld2, fld3 from tbl
12 group by fld1,fld2,fld3
13 having count(1) > 1
14 order by fld1, fld2, fld3
15 /
FLD1 FLD2 FLD3
SQL> --Q4
SQL> with tbl as
2 (select 1 fld1, 1 fld2, 1 fld3 from dual
3 union all
4 select 1 fld1, 1 fld2, 2 fld3 from dual
5 union all
6 select 1 fld1, 1 fld2, 2 fld3 from dual
7 union all
8 select 1 fld1, 1 fld2, 3 fld3 from dual
9 union all
10 select 1 fld1, 2 fld2, 3 fld3 from dual
11 union all
12 select 1 fld1, 3 fld2, 3 fld3 from dual)
13 select fld1, fld2, fld3 from tbl
14 order by fld1, fld2, fld3
15 /
FLD1 FLD2 FLD3
1 1 1
1 1 2
1 1 2
1 1 3
1 2 3
1 3 3
6 rows selected
SQL> --Q5
SQL> with tbl as
2 (select 1 fld1, 1 fld2, 1 fld3 from dual
3 union all
4 select 1 fld1, 1 fld2, 2 fld3 from dual
5 union all
6 select 1 fld1, 1 fld2, 2 fld3 from dual -- inserted duplicate row
7 union all
8 select 1 fld1, 1 fld2, 3 fld3 from dual
9 union all
10 select 1 fld1, 2 fld2, 3 fld3 from dual
11 union all
12 select 1 fld1, 3 fld2, 3 fld3 from dual)
13 select fld1, fld2, fld3, count(1) from tbl
14 group by fld1,fld2,fld3
15 order by fld1, fld2, fld3
16 /
FLD1 FLD2 FLD3 COUNT(1)
1 1 1 1
1 1 2 2
1 1 3 1
1 2 3 1
1 3 3 1
SQL> --Q6
SQL> with tbl as
2 (select 1 fld1, 1 fld2, 1 fld3 from dual
3 union all
4 select 1 fld1, 1 fld2, 2 fld3 from dual
5 union all
6 select 1 fld1, 1 fld2, 2 fld3 from dual -- inserted duplicate row
7 union all
8 select 1 fld1, 1 fld2, 3 fld3 from dual
9 union all
10 select 1 fld1, 2 fld2, 3 fld3 from dual
11 union all
12 select 1 fld1, 3 fld2, 3 fld3 from dual)
13 select fld1, fld2, fld3 from tbl
14 group by fld1,fld2,fld3
15 having count(1) > 1
16 order by fld1, fld2, fld3
17 /
FLD1 FLD2 FLD3
1 1 2
SQL> Q1. As you may see we have an bunch of data where each row is unique combination of the columns value.
Q2. lets try to group it by fld1 and fld2 and fld3 columns. We don't expect any miracle and got the same data as Q1. Why? Because each row is unique combination(group) in scope of fld1, fld2, fld3 - count(1) exactly shows us that.
Q3. Q2 is explanation why we got no rows filter (having count(1) > 1)because the result of the clause is always false.
Q4. Lets put some duplication.
Q5. Now we got some new result. Count shows us group with more then one rows.
Q6. Shows us exact group which we've found in Q5.
Maybe you are looking for
-
How to upload file using *cl_gui_frontend_services* method
hi i want to upload an image file using this method and i want to save it in MIME Repository (/SAP/BC/BSP/SAP/PRASHANT) DATA: itab TYPE TABLE OF sflight. CALL METHOD cl_gui_frontend_services=>gui_upload EXPORTING filename = 'C:\t
-
HT201302 Transferring large video file from Iphone
My video file is extremely large and won't transfer by click and drag to hard drive. I have tried every way possible. Any suggestions?
-
Can u examine me before my teacher
i have an exam on thursday.this exam will include (loops only)and the main idea in application and applet. so plz help me to be ready for this exam.and that's by giving me some questions and tricks. now i'll go to my university so plz i wish finding
-
Syncing Firefox across Mac and iPad mini 2
Hi there, I do a *lot* of research and web browsing on my Mac Air with Firefox (google chrome seemed to consistently freeze my macbook air forcing me to hard restart). I currently have 2-3 windows with a good 30 tabs or so open on each. (I know, I kn
-
Strange colour spots (red&green) appear after RAW files converted to JPEG, anyone know how to fix it? Thanks.