Simple sql to mdx query using the max fn
I'm using the MDX Max fn to get the max of a certain value but now I want get max for a certain pair of values and not all, how could i write this in mdx as a calculation?
More details: For a certain pair of status and substatus (status=1, substatus=1) from a trans dimension table i want to get the max insertionid (attribute in trans measure table). How would you guys suggest I go about this?
I'm new to mdx and I'm converting a whole sql statement to a measure not to include it as a named query for performance concerns!
If needed this is the sql query im converting:
SELECT TOP (1) InsertionDT
FROM dbo.TransTasksFFMS_GVT AS TSI
WHERE (TaskCode = T.TaskCode) AND (TaskStatus = 1) AND (TaskSubStatus = 1)
ORDER BY InsertionDT) AS RegistrationTimeWithoutConversion
Another way to think of this is how to apply a certain measure only on certain values and not all values in the browser.
Hi Junior,
According to your description, you want to get the max value by using MDX query, right? Since no know your cube detail information, we cannot convert this T-SQL to MDX query. Here is a sample MDX query for your reference. The query below returns the Sale
Amount measure and the MaxValue calculated member. The MaxValue calculated member takes the maximum value for members of the Fiscal Year level in the Fiscal hierarchy of the Date dimension.
WITH
MEMBER [Measures].[MaxValue] AS
MAX([Date].[Fiscal].[Fiscal Year].Members, [Measures].[Sales Amount])
SELECT
{[Measures].[Sales Amount],[Measures].[MaxValue]} ON COLUMNS,
{[Date].[Fiscal].[Fiscal Year].Members} ON ROWS
FROM
[Adventure Works]
Reference:Max (MDX)
Regards,
Charlie Liao
TechNet Community Support
Similar Messages
-
How to get cm:search to use the max attribute when creating the SQL query?
When we use the max attribute in the cm:search tag, it does not seem to honor the max attribute when creating the SQL query. However, the result returned from the tag is limited to the number specified by the max attribute. Then the tag seems to work as intended, but the performance will be sub optimal when the SQL query returns unnecessary rows to the application.
We use the cm:search tag to list the latest news (ordered by date), and with the current implementation we have to expect a decrease in performance over time as more news is published. But we can’t live with that. We need to do the constraint in the SQL query, not in the application.
The sortBy attribute of cm:search is translated to “order by” in the SQL query, as expected.
Is it possible to get cm:search to generate the SQL query with an addition of “where rownum <= maxRows”?Hi Erik,
The behavior of a repository in regards to the search tag's max results parameter is dependent on the underlying repository's implementation. That said, the OOTB repository in WLP does augment the generated SQL to limit the number of rows returned from the database. This is done in the parsing logic. This behavior may differ with other repository implementations.
-Ryan -
How to generate mdx query using C#
I am new to mdx query and i am very curious about mdx query generation using c# so i searched for any demo or open source then i found
Ranet.olap, which is providing what i need. After taking the dlls i tried to incorporate them in my code. I am pasting my full
console code which should generate mdx query but it's not doing so, Am i doing something wrong.
using System;
using System.Collections.Generic;
using Microsoft.AnalysisServices.AdomdClient;
using Ranet.Olap.Core.Managers;
using Ranet.Olap.Core.Metadata;
using Ranet.Olap.Core.Types;
namespace MDX
class Program
static void Main(string[] args)
startWork();
public static void startWork()
string connString = "Provider=MSOLAP.3; Data Source=localhost;Initial Catalog=AdventureWorkDW2008R2;Integrated Security=SSPI;";
CubeDef cubes;
AdomdConnection conn = new AdomdConnection(connString);
conn.Open();
cubes = conn.Cubes.Find("AdventureWorkCube");
Ranet.Olap.Core.Managers.MdxQueryBuilder mdx = new Ranet.Olap.Core.Managers.MdxQueryBuilder();
mdx.Cube = cubes.Caption;
List<Ranet.Olap.Core.Wrappers.AreaItemWrapper> listColumn = new List<Ranet.Olap.Core.Wrappers.AreaItemWrapper>();
List<Ranet.Olap.Core.Wrappers.AreaItemWrapper> listRow = new List<Ranet.Olap.Core.Wrappers.AreaItemWrapper>();
List<Ranet.Olap.Core.Wrappers.AreaItemWrapper> listData = new List<Ranet.Olap.Core.Wrappers.AreaItemWrapper>();
//Column area
Dimension dmColumn = cubes.Dimensions.Find("Dim Product");
Microsoft.AnalysisServices.AdomdClient.Hierarchy hColumn = dmColumn.Hierarchies["English Product Name"];
//hierarchy properties
List<PropertyInfo> lPropInfo = new List<PropertyInfo>();
foreach (var prop in hColumn.Properties)
PropertyInfo p = new PropertyInfo();
p.Name = prop.Name;
p.Value = prop.Value;
lPropInfo.Add(p);
Ranet.Olap.Core.Wrappers.AreaItemWrapper areaIColumn = new Ranet.Olap.Core.Wrappers.AreaItemWrapper();
areaIColumn.AreaItemType = AreaItemWrapperType.Hierarchy_AreaItemWrapper;
areaIColumn.Caption = hColumn.Caption;
areaIColumn.CustomProperties = lPropInfo;
listColumn.Add(areaIColumn);
//Rows Area
Dimension dmRow = cubes.Dimensions.Find("Due Date");
Microsoft.AnalysisServices.AdomdClient.Hierarchy hRow = dmRow.Hierarchies["English Month Name"];
List<PropertyInfo> lRowPropInfo = new List<PropertyInfo>();
foreach (var prop in hRow.Properties)
PropertyInfo p = new PropertyInfo(prop.Name,prop.Value);
lRowPropInfo.Add(p);
Ranet.Olap.Core.Wrappers.AreaItemWrapper areaIRow = new Ranet.Olap.Core.Wrappers.AreaItemWrapper();
areaIRow.AreaItemType = AreaItemWrapperType.Hierarchy_AreaItemWrapper;
areaIRow.Caption = hRow.Caption;
areaIRow.CustomProperties = lRowPropInfo;
listRow.Add(areaIRow);
//Measure Area or Data Area
Measure ms = cubes.Measures.Find("Order Quantity");
Ranet.Olap.Core.Wrappers.AreaItemWrapper areaIData = new Ranet.Olap.Core.Wrappers.AreaItemWrapper();
areaIData.AreaItemType = AreaItemWrapperType.Measure_AreaItemWrapper;
areaIData.Caption = ms.Caption;
List<PropertyInfo> lmpropInfo = new List<PropertyInfo>();
foreach (var prop in ms.Properties)
PropertyInfo p = new PropertyInfo(prop.Name, prop.Value);
lmpropInfo.Add(p);
areaIData.CustomProperties = lmpropInfo;
listData.Add(areaIData);
mdx.AreaWrappersColumns = listColumn;
mdx.AreaWrappersRows = listRow;
mdx.AreaWrappersData = listData;
string mdxQuery = mdx.GenerateMdxQuery();
conn.Close();Hi mkm1,
According to your description, you want to use C# code to generate MDX Query. Right?
In Analysis Servcies, we just need to use "Microsoft.AnalysisServices.AdomdClient.dll" to open connection to SSAS database and retrieve data from cube. Here are some sample code about executing MDX query using C#.
Dim objConnection As New AdomdConnection("Data Source=localhost;Initial Catalog=Adventure Works DW 2008;")
Dim objCommand As New AdomdCommand()
Dim objDatatable As New DataTable
Dim strCommand As String
strCommand = "SELECT [Measures].[Internet Sales Amount] ON COLUMNS, "
strCommand = strCommand & " [Date].[Calendar].[Calendar Year] ON ROWS"
strCommand = strCommand & " FROM [Adventure Works]"
objConnection.Open()
objCommand.Connection = objConnection
objCommand.CommandText = strCommand
Dim objDataAdapter As New AdomdDataAdapter(objCommand)
objDataAdapter.Fill(objDatatable)
objConnection.Close()
Since your code is more related to a third party API, we suggest you post your question to Rnet.
Reference:
Microsoft.AnalysisServices.AdomdClient Namespace
If you have any question, please feel free to ask.
Simon Hou
TechNet Community Support -
Why isn't my query using the index?
I have a query that inserts values for engines in a grid; it uses a static date table to determine the day in week, or
week in year (depending on different standards, the DBA can configure this table to their business's likings). I have
two indexes on this table:
create table d_date (
date_key number(5) not null,
sql_calendar_date timestamp(3) null,
year_id number(5) null,
month_id number(3) null,
day_id number(3) null,
year_end_biz_date timestamp(3) null,
qtr_end_biz_date timestamp(3) null,
month_end_biz_date timestamp(3) null,
week_end_biz_date timestamp(3) null,
quarter_id number(3) null,
week_id number(3) null,
day_in_year number(5) null,
day_in_month number(3) null,
day_in_week number(3) null,
month_name char(3) null,
day_in_week_name char(3) null,
month_type_code char(1) null,
week_type_code char(1) null,
date_type_code char(1) null,
weekend_flag char(1) null,
holiday_flag char(1) null,
from_datetime timestamp(3) null,
to_datetime timestamp(3) null,
current_flag char(1) null,
constraint d_date_pkey primary key (date_key)
) tablespace dim;
create index d_date_dy on d_date(year_id, day_in_year) tablespace_dim_idx;
create index d_date_ww on d_date(year_id, week_id) tablespace_dim_idx;Now, when I run a query to insert the week id into a table based on two values, the year_key and day_in_year_key,
it should use the d_date_dy index correct?
Here is what the query looks like:
INSERT INTO F_ENGINE (YEAR_KEY,MONTH_KEY,WEEK_IN_YEAR_KEY,DAY_IN_YEAR_KEY,DAY_IN_MONTH_KEY,HOUR_IN_DAY_KEY, Q_HOUR_IN_DAY_KEY,
GRID_KEY,ENGINE_KEY,TIME_STAMP,ENGINE_CPU_UTIL,ENGINE_CPU_GRID_UTIL,MEMORY_TOTAL_BYTE, MEMORY_FREE_BYTE,DISK_FREE_MEGABYTE,
PROCESS_COUNT,ENGINE_ID,GRID_ID,GRID_NAME,BATCH_ID,RECORD_VIEWABLE_F)
SELECT EXTRACT(YEAR FROM START_DATETIME),EXTRACT(MONTH FROM START_DATETIME), DD.WEEK_ID,
TO_NUMBER(TO_CHAR(START_DATETIME, 'DDD')), EXTRACT(DAY FROM START_DATETIME),EXTRACT(HOUR FROM START_DATETIME),
FLOOR(EXTRACT(MINUTE FROM START_DATETIME)/15)*15,DG.GRID_KEY,DE.ENGINE_KEY, START_DATETIME,CPU_UTIL,DS_CPU,MEMORY,
FREE_MEMORY,FREE_DISK,PROCESSES,ID,PE.GRID,DG.GRID_NAME,:B1 ,1
FROM P_ENGINE PE, D_GRID DG, D_ENGINE DE, D_DATE DD
WHERE PE.GRID = DG.GRID_ID AND DG.CURRENT_FLAG = 'Y' AND PE.ID = DE.ENGINE_ID AND DE.GRID_KEY = DG.GRID_KEY AND
DE.CURRENT_FLAG = 'Y' AND PE.BATCH_ID = :B1 AND DD.YEAR_ID = EXTRACT(YEAR FROM START_DATETIME) AND
DD.DAY_IN_YEAR = TO_NUMBER(TO_CHAR(START_DATETIME,'DDD'))
ORDER BY EXTRACT(YEAR FROM START_DATETIME),EXTRACT(MONTH FROM START_DATETIME),
EXTRACT(DAY FROM START_DATETIME),EXTRACT(HOUR FROM START_DATETIME),FLOOR(EXTRACT(MINUTE FROM START_DATETIME)/15)*15,
DG.GRID_KEY,DE.ENGINE_KEY
Here is the explain plan:
Operation Object Object Type Order Rows Size (KB) Cost Time (sec) CPU Cost I/O Cost
INSERT STATEMENT
SORT ORDER BY
HASH JOIN
HASH JOIN
HASH JOIN
TABLE ACCESS FULL D_GRID TABLE 1 2 0.316 3 1 36887 3
TABLE ACCESS FULL D_ENGINE TABLE 2 10 0.410 3 1 42607 3
PARTITION LIST SINGLE 5 1434 344.496 9 1 2176890 9
TABLE ACCESS FULL P_ENGINE TABLE 4 1434 344.496 9 1 2176890 9
TABLE ACCESS FULL D_DATE TABLE 7 7445 283.550 19 1 3274515 18Now it is obviously not using the index for the d_date table since it is doing a full table access.
Does this have something to do with the fact that I am using extract(), to_number(), to_char() functions in my WHERE clause that it is not allowing the use of the index?
Any help would be greatly appreciated. Thanks.
-TimIt's difficult to tell just from this. For one thing, you didn't post your query using the forum format tags, so it's hard to read and you didn't post your Oracle version.
In the query, you don't always prefix columns with the table alias. That makes it impossible for us (and maintainers of this code) to know at a glance which table a column is in.
It's possible that performing functions on a column will disable the index. Do your other tables have indexes? Do you have updated statistics on all the tables?
The main reason the optimizer will not use an index is because it thinks it cheaper not to. -
Simple question. Can i use the iPad charger in my iPod touch?
Simple question. Can i use the iPad charger in my iPod touch?
Yes. I use mine all the time.
-
Query using the SQL 'go' command on a JAVA code
Hi,
I am trying to create a new database on MS SQL and at the same time verify whether the data base exist already and then add a new table. The query statement works well on the query windows on MS SQL, but when the query is place using a JAVA code it gives the following error:
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'go'.
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'go'.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(Unknown Source)
at DataBaseCreator.main(DataBaseCreator.java:30)
I have to add that if I only query: "CREATE DATABASE NameOfDatabase" the new data base is created without a problem using JAVA, but when I try to use the following query, I got the error message.
"USE Master "
+ "IF EXISTS (SELECT * FROM SysDatabases WHERE NAME='DatesTemps') "
+ " DROP DATABASE DatesTemps"
+ " go "
+ " CREATE DATABASE DatesTemps22 "
+ " go"
+ " USE DatesTemps "
+ " CREATE TABLE Fable ( "
+ " FableID INT NOT NULL CONSTRAINT FablePK PRIMARY KEY NONCLUSTERED, "
+ " Title VARCHAR(50) NOT NULL, "
+ " Moral VARCHAR(100) NOT NULL, "
+ " FableText VARCHAR(1536) NOT NULL, "
+ " BlobType CHAR(3) NULL DEFAULT 'doc', "
+ " Blob IMAGE NULL DEFAULT NULL )"
If it is useful my complete code is the following, I appreciate in advance your comments.
import java.sql.Connection;
import java.sql.Statement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Calendar;
import java.util.GregorianCalendar;
public class DataBaseCreator {
public static void main (String[] args)
Connection Time =null;
Statement stmt = null;
String data = "jdbc:odbc:DataBaseCreation";
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Time= DriverManager.getConnection(data,"","");
stmt = Time.createStatement();
//String query;
//java.sql.Timestamp ts1 = new java.sql.Timestamp(((3*60)+58)*60*1000);
// System.out.println(ts1 + " This is a Time Stamp");
ResultSet rec = stmt.executeQuery(
"USE Master "
+ "IF EXISTS (SELECT * FROM SysDatabases WHERE NAME='DatesTemps') "
+ " DROP DATABASE DatesTemps"
+ " go "
+ " CREATE DATABASE DatesTemps22 "
+ " go"
+ " USE DatesTemps "
+ " CREATE TABLE Fable ( "
+ " FableID INT NOT NULL CONSTRAINT FablePK PRIMARY KEY NONCLUSTERED, "
+ " Title VARCHAR(50) NOT NULL, "
+ " Moral VARCHAR(100) NOT NULL, "
+ " FableText VARCHAR(1536) NOT NULL, "
+ " BlobType CHAR(3) NULL DEFAULT 'doc', "
+ " Blob IMAGE NULL DEFAULT NULL )"
catch( Exception e )
System.err.println( e );
e.printStackTrace();
finally
try
stmt.close();
Time.close();
catch( Exception e )
System.err.println( e );
}Ok, first of all thanks for your answer, now what I want to do is the following:
1) I need to input ((retrieve) every minute some data (Date and Temperature), that I will get from and external device, this is not part of this code.
2) I want to store that data (Date and Temp) on a data base, here where I need the command to create the data base and to verify whether that data base already exists. In case it has already been created then create new table(s) on it. If it doesn't exist then create and then create new tables.
3) Each Day (at yyyy mm dd 00:00:00:000 will create a new table, and the name of this table will be yyyymmdd.
4) Then every minute the java code will retrieve the data and add it to the table in the data base.
5) That will be a close loop that will be running until the user interrupt it.
I haven't make the communication code yet, in order to test my code I was thinking to retrieve the data from another data base. This would be just to verify that the JAVA sequence is able to retrieve the data every minute and create new data base and tables.
For the record I am able to send the queries and retrieve information from SQL running the code in eclipse, that will cover your first observation.
I am quite new in the forum I am sorry I didn't get the use of code tags.
Sorry again as I said I am quite new on this, what's a DDL statement.
Thanks. -
MDX Query using BottomCount to limit Median calculation returns null
I'm building a new cube that includes some person age values that aren't useful when summed, but are
useful when the median is determined. The measure group that contains the measure for the age has a 1-1 relationship with a dimension in the cube because both use the same table as the source. This is important because I use the key attribute of the dimension
as the set expression in the Median function to prevent any summation before the median is found. Here is the code for the original median calculation:
MEMBER Measures.[Median Age] AS
MEDIAN(
[Placement Dimension].[Id Removal Episode Fact].Members,
[Measures].[Age At Removal Months]
This median naturally represents the half-way point in the series of values. My analysts have also requested
median-type values at the quarter and three-quarter points in the same series. I've been able to accomplish this for the three-quarter point by nesting the TopCount function in the set expression of the Median function to limit the set to the last half of
the records and then find the median point like this:
MEMBER Measures.[75th Percentile] AS
MEDIAN(
TOPCOUNT(
[Placement Dimension].[Id Removal Episode Fact].MEMBERS
,Measures.[Episode Count] / 2
,Measures.[Age At Removal Months]
,Measures.[Age At Removal Months]
However, my attempt to use the BottomCount function in the same way as TopCount to find the quarter point
in the whole data set by limiting the calculation's set to the first half of the data always returns null. Here is how I've formed the code:
MEMBER Measures.[25th Percentile] AS
MEDIAN(
BOTTOMCOUNT(
[Placement Dimension].[Id Removal Episode Fact].MEMBERS
,Measures.[Episode Count] / 2
,Measures.[Age At Removal Months]
,Measures.[Age At Removal Months]
And here is the query that returns the values:
SELECT
Measures.[Episode Count]
,Measures.[Median Age]
,Measures.[25th Percentile]
,Measures.[75th Percentile]
} ON 0
,[Date Begin].[Calendar Hierarchy].Year.&[2011]:[Date Begin].[Calendar Hierarchy].Year.&[2014] ON 1
FROM [POC Cube]
WHERE
[Age at Removal Mos].[Age in Years List].[Age Year].&[0]:[Age at Removal Mos].[Age in Years List].[Age Year].&[5]
I don't know why the end result is always null. I don't have any null values in the data for this measure, and I know what values I should be seeing because I've found the median records manually in results from a SQL Server query. I've tried using TopCount
and multiplying Measures.[Age At Removal Months] in the TopCount function by -1 to workaround the descending sort, but I still get nulls. I've also tried separating these queries out so the quarter point and three-quarter point calculations aren't run together,
but I still get nulls for the quarter point calculation.
I'm open to any help fixing this situation by modifying my current code or by using alternate methods, but the end result has to be dynamic enough to be used as a calculation in the cube. Thanks!The links might helps.
http://technet.microsoft.com/en-us/library/ms144864.aspx
http://www.mssqltips.com/sqlservertip/3034/sql-server-analysis-services-ssas-2012-top-and-bottom-functions/
http://www.sqlservercentral.com/blogs/bradleyschacht/2012/03/12/mdx-functions-bottomcount/ -
Why is my query using the wrong index?
Hi SQL Tuning experts....
I'm running Oracle 11.2.0.2 EE on Solaris 10
I've just checked my top SQL statements in OEM and drilling down on the top query of the list, I decided to run SQL Advisor on the query.
Low and behold, it came back with a profile that gives me a 99.9% improvement.
When I compared the original plan to the new plan the only difference is that the SQL Advisor is using a different index.
Now, the dumb DBA question: why? why is Oracle picking the wrong index?
original plan
SELECT STATEMENT
COUNT STOPKEY
VIEW
SORT ORDER BY STOPKEY
TABLE ACCESS BY INDEX ROWID ARADMIN.T2179 TABLE
INDEX RANGE SCAN ARADMIN.T2179_C3 INDEXnew plan...
SELECT STATEMENT
COUNT STOPKEY
VIEW
SORT ORDER BY STOPKEY
TABLE ACCESS BY INDEX ROWID ARADMIN.T2179 TABLE
INDEX RANGE SCAN ARADMIN.T2179_C536870923 INDEXThe stats:
table has approx. 3.3Mil rows
table segment is approx. 15G (5G of it is reclaimable space, but probably not related)
table has fresh stats and indexes have been recently rebuilt
indexes in this discussion are both b-tree
the C3 column is number(15) with 2836897 distinct rows
the C536870923 columns is VARCHAR2(255) with 1080533 distinct values
Here is the actual query:
SELECT *
FROM (
SELECT T2179.C1,C536871040,C536871037,C536870944,C3,C536870918,C536870919,
C536870924,C536871048,C536871049,C536871050,C536870926,C536870925,
C536870916,C4,C536871275,C536871095,C536870913
FROM T2179
WHERE ((T2179.C536870923 = :"SYS_B_0") AND (T2179.C3 > :"SYS_B_1")) ORDER BY C1 DESC )
WHERE ROWNUM <= :"SYS_B_2"Obviously this is a good example of why we should use profiles. :-)
Edited by: ji li on Feb 14, 2013 1:32 PM
Sorry... I should have included the plan output
I'm guessing this has something to do with the cardinality of the data in the columns.Dom.... I've already posted most everything. Here are the relevant init params and misc stuff you are asking for.
NAME TYPE VALUE
object_cache_optimal_size integer 102400
optimizer_capture_sql_plan_baselines boolean FALSE
optimizer_dynamic_sampling integer 2
optimizer_features_enable string 11.2.0.2
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 100
optimizer_mode string ALL_ROWS
optimizer_secure_view_merging boolean TRUE
optimizer_use_invisible_indexes boolean FALSE
optimizer_use_pending_statistics boolean FALSE
optimizer_use_sql_plan_baselines boolean TRUE
plsql_optimize_level integer 2
db_file_multiblock_read_count integer 128
db_block_size integer 8192
cursor_sharing string FORCE
SNAME PNAME PVAL1 PVAL2
SYSSTATS_INFO STATUS COMPLETED
SYSSTATS_INFO DSTART 12-04-2012 12:28
SYSSTATS_INFO DSTOP 12-04-2012 15:28
SYSSTATS_INFO FLAGS 0
SYSSTATS_MAIN CPUSPEEDNW 2992.2746781116
SYSSTATS_MAIN IOSEEKTIM 10
SYSSTATS_MAIN IOTFRSPEED 4096
SYSSTATS_MAIN SREADTIM 48027.271
SYSSTATS_MAIN MREADTIM 37217.102
SYSSTATS_MAIN CPUSPEED 2978
SYSSTATS_MAIN MBRC 0
SYSSTATS_MAIN MAXTHR 400782336
SYSSTATS_MAIN SLAVETHR 1403904
13 rows selected.
QL> l
1 SELECT * FROM (
2 SELECT
3 T2179.C1,
4 C536871040,
5 C536871037,
6 C536870944,
7 C3,
8 C536870918,
9 C536870919,
10 C536870924,
11 C536871048,
12 C536871049,
13 C536871050,
14 C536870926,
15 C536870925,
16 C536870916,
17 C4,
18 C536871275,
19 C536871095,
20 C536870913
21 FROM aradmin.T2179
22 WHERE (
23 (C536870923 = '300885690')
24 AND
25 (C3 > '1360938353')
26 )
27 ORDER BY C1 DESC )
28* WHERE ROWNUM <= 1
no rows selected
Elapsed: 00:00:00.01
Execution Plan
Plan hash value: 2768254526
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 2315 | 6 (17)| 00:00:01 |
|* 1 | COUNT STOPKEY | | | | | |
| 2 | VIEW | | 1 | 2315 | 6 (17)| 00:00:01 |
|* 3 | SORT ORDER BY STOPKEY | | 1 | 226 | 6 (17)| 00:00:01 |
|* 4 | TABLE ACCESS BY INDEX ROWID| T2179 | 1 | 226 | 5 (0)| 00:00:01 |
|* 5 | INDEX RANGE SCAN | T2179_C3 | 1 | | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter(ROWNUM<=1)
3 - filter(ROWNUM<=1)
4 - filter("C536870923"='300885690')
5 - access(SYS_OP_DESCEND("C3")<HEXTORAW('3AF1C2A1ABC9FF') )
filter(SYS_OP_UNDESCEND(SYS_OP_DESCEND("C3"))>1360938353)
Statistics
0 recursive calls
0 db block gets
2615 consistent gets
0 physical reads
0 redo size
1538 bytes sent via SQL*Net to client
513 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
0 rows processed -
Hello,
I use Entity Framework code first approach.
My project is working fine with SQL Server. But, I want to access Oracle too. I want to switch SQL Server and Oracle in run time.
I am able to access Oracle using "Oracle.ManagedDataAccess.EntityFramework.dl" in a new project.
But, Is this possible to access SQL Server and Oracle in the same project.
Thanks,
MuruganThis should be possible with a Code-First workflow. In Code-First the database mapping layer is generated at runtime.
David
David http://blogs.msdn.com/b/dbrowne/ -
How to find out if your query uses the indexes?
How can one tell if the query being issued is using your indexes or doing full table scans?
Thank you.Thank you.
Ok, let me see if I understand it. So, having an
index may not speed things up.True
Full table scans are not bad at all -- as I have it
in my head. The query I ran before was: select *
from table1;In that case an index would only slow things down; you are asking it to get all the information from the table - it has to read all of the table ( a full scan).
>
So full table scans and index have to do with the db
block size and the size of the row correct?
Block size and row size don't have a huge amount to do with it, but they do play a role.
Let me ask: How does one know the size of a row and
then the best option for the db blocks? Block size is a global setting (at the tablespace level I think). You would not likely change the block size based on the average row length in any one table. It would be about the last thing you might look at in terms of tuning (though you might consider it up-front if you had a huge amount of very predictable data).
>
And if, I create indexes and queries have the where
clause and the database uses full table scans then
does it means that either:
The database believes that the best execution plan is
to either do FULL SCANS OR USE INDEXES -- ALL UPTO
THE DATABASE?
No. There is another piece of information that the database needs to make good decisions. If for example you have a WHERE clause "WHERE not_paid = 1" and you have an index on not_paid. To make a good decision the database needs to know about how many of the rows are likely to be not_paid =1. If it's 90% then a full table scan will be cheaper than looking up the addresses of 90% of the rows and then getting the data. If it's 10% using the index will be cheaper. You need to use Analyze Tables to get the database to store this information. Looks like you need to use a bit of time with the manuals.
Jon
-J -
SQL QUERRy (how to use the SQVI)
Hi all,
can anyone explain the process and how to use the Tcode SQVI.....
thanks in advance
srinivas...thanks for imm responce....
as per ur mail ...
If a report got created through SQVI Transaction it will not allows you to transport..
the same senario will effect to the Tcodes SQ01,SQ02,SQ03.....
could you please look into below my question also..can any one please responce to this,,,,
The below link will explain to genereate the normal or ALV report using ABAP query without any programming language.i have few questions......
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/40bec8da-4cd8-2910-27a9-81f5ce10676c
1.here in this link pdf doc explained how to get the data in two tables usuing ABAP quesry,,,
is it possible for getting the data from more than two tables and how ,canone please guide me....
2.using ABAP query i got the ALV single grid report ,is it possible to get more than single grid usuingABAP query ....?
3.using ABAP query i got the ALV single grid report then how to give the print and how copy and paste in the edit pad....
note : the above PDF link step by step is helpfull for generating report using Tcodes like SQ01,SQ02,SQ03.
can anyone provide the similar type pdf documents for generating report using Tcode SQVI...?
thanks in advance
Srinivas........... -
How to avoid the query using the index?
select *from cstb_cut ;
cust_id cust_name
10001 xxxx
10002 yyyy
10003 zzzz
Please find the above table and 10000 records are there in that table and also one index was there on cust_id.
but my query don't want to use the index?how it will be done?Hi,
DEVI suvarna wrote:
select *from cstb_cut ;
cust_id cust_name
10001 xxxx
10002 yyyy
10003 zzzz
Please find the above table and 10000 records are there in that table and also one index was there on cust_id.
but my query don't want to use the index?how it will be done?
The index doesn't help for this query, so it's not used.
The main purpose of indexes is the help find a small number (like 1) of rows quickly. You're asking for all rows; getting each one through the index would be slower than just getting all of them directly.
Sometimes (but not here) the index can be used instead of the table, when the index contains all the data you need from the table. An index on cust_id doesn't tell you anything about any other column, such as cust_name. Since you asked to have all columns displayed, it has to fetch data from the table, not the index. -
How to use the max volume option
Well my ipod was pretty loud before and now i have dicked with that setting and sitting in my room with just a tv on i have it almost all the way up. What should the max volume be set at or what should i do to get that volume back?
If your talking about volume limit, you just go to settings and reset it. If you set a password you forgot, the only way to unluck it is to restore the ipod. That will make it loose all the data on it.
-
How to use the MAX DATE condition in WHERE CLAUSE FILEDS
Hi,
I am trying to fetch the result for getting maximun date but when i try to execute the query i am getting the error as follows.
CONDITION : trunc(max(RD.DATERECEIVED)) BETWEEN TO_DATE('01/08/2011','DD/MM/YYYY') AND TO_DATE('01/08/2011','DD/MM/YYYY')
ERROR: Group function is not allowed here.
CHEERS,
PRABU AMMAIAPPANI see a couple of problems here.
First, what you posted below is not a syntactically valid query. It seems to be part of a larger query, specifically, this looks to be only the GROUP BY clause of a query.
Prabu ammaiappan wrote:
Hi,
I Have a group function in the Query. Below is the Query i have used it,
GROUP BY S.FREIGHTCLASS,
R.CONTAINERKEY,
S.SKU,
S.DESCR ||S.DESCRIPTION2,
S.PVTYPE,
RD.LOTTABLE06,
R.WAREHOUSEREFERENCE,
RD.TOLOC,
R.ADDWHO,
R.TYPE,
S.CWFLAG,
S.STDNETWGT,
S.ORDERUOM,
R.ADDDATE,
C.DESCRIPTION,
(CASE WHEN P.POKEY LIKE '%PUR%' THEN 'NULL' ELSE to_char(P.PODATE,'dd/mm/yyyy') END),
NVL((CASE WHEN R.ADDWHO='BOOMI' THEN RDD.SUPPLIERNAME END),SS.COMPANY),
RDD.BRAND,
S.NAPA,
RD.RECEIPTKEY,
R.SUSR4,
P.POKEY,
RDD.SUSR1,
r.STATUS, DECODE(RDD.SUSR2,' ',0,'',0,RDD.SUSR2),
rd.SUSR3Second, the answer to your primary question, "How do I add a predicate with with a MAX() function to my where clause?" is that you don't. As you discovered, if you attempt to do so, you'll find it doesn't work. If you stop and think about how SQL is processed, it should make sense to you why the SQL is not valid.
If you want to apply a filter condition such as:
trunc(max(RD.DATERECEIVED)) BETWEEN TO_DATE('01/08/2011','DD/MM/YYYY') AND TO_DATE('01/08/2011','DD/MM/YYYY')you should do it in a HAVING clause, not a where clause:
select ....
from ....
where ....
group by ....
having max(some_date) between this_date and that_date;Hope that helps,
-Mark -
Using the max function in a inner joined statement
I am trying to take from a database with two joined tables various datas from the record belonging to paul that has the highest entry number.
String query = "SELECT Table1.name, Table1.idNumber, Table2.Address Table2.entryNum FROM Table1 INNER JOIN Table2 ON Table1.idNumber = Table2.idNumber WHERE Table2.entryNum = max ( Table2.entryNum) AND Table1.name = 'Paul'";
The error message i get is.
Cannot have aggregate function in WHERE clause
Thanks for any helpI am trying to take from a database with two joined
tables various datas from the record belonging to paul
that has the highest entry number.SELECT
Table1.name,
Table1.idNumber,
Table2.Address
Table2.entryNum
FROM Table1 INNER JOIN Table2 ON Table1.idNumber = Table2.idNumber
WHERE Table2.entryNum =
( select max( Table2.entryNum) from table1, table2
where table1.idNumber=table2.idNumber
AND Table1.name = 'Paul'" );
Maybe you are looking for
-
How do I set up a second itunes account on the same laptop?
Can you have 2 separate itune accounts on the same laptop? How do you set it up?
-
Can One Sync a Smart Mailbox to .Mac???
I use a smart mailbox for all emails that need attending (if message is flagged.& if in Inbox) now, I would like to have that "smart" folder sync to my .mac account somehow, as it is IMAP there must be a way... any ideas? I realise anything in my .ma
-
How do Import a csv file that contains strings
I have a file that contains numbers as US formmated $$$ such as $1,123,123,123 I have a perl script on one of our linux servers that creates the csv file as "Total Dollars","$1,123,123,123","some other string","etc" but when I import the file into
-
Trouble in passing variable to flash
I want to pass the current login username from php to flash. So I have written the following code. PHP Code: <?php require_once('C:\xampp\htdocs\moodle\config.php'); $r=$USER->username; echo "val=$r"; ?> Actionscript code var myLoader:URLL
-
Possible values for WDY_ATTRIBUTE_FORMAT_PROP-DATE_FORMAT?
Hi, where can I lookup possible values for formatting a date typed field using WDY_ATTRIBUTE_FORMAT_PROP-DATE_FORMAT? I did not find any documentation so far.